Skip to content

Commit

Permalink
migrated to fragments backport
Browse files Browse the repository at this point in the history
  • Loading branch information
commonsguy committed Feb 25, 2018
1 parent f785f4f commit d835daf
Show file tree
Hide file tree
Showing 87 changed files with 391 additions and 384 deletions.
19 changes: 17 additions & 2 deletions ActionBar/SearchView/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion '26.0.2'
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation "com.android.support:support-fragment:27.0.2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

package com.commonsware.android.ab.search;

import android.app.ListFragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.Menu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

package com.commonsware.android.ab.search;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class ActionBarFragmentActivity extends Activity {
public class ActionBarFragmentActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (getFragmentManager().findFragmentById(android.R.id.content) == null) {
getFragmentManager().beginTransaction()
if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content,
new ActionBarFragment()).commit();
}
Expand Down
8 changes: 4 additions & 4 deletions AlarmManager/AlarmClock/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ repositories {

dependencies {
implementation 'org.greenrobot:eventbus:3.0.0'
implementation 'com.android.support:support-v13:25.0.3'
implementation 'com.commonsware.cwac:wakeful:1.0.+'
implementation "com.android.support:support-fragment:27.0.2"
implementation 'com.commonsware.cwac:wakeful:1.1.0'
}

android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

package com.commonsware.android.alarmclock;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class EventDemoActivity extends Activity {
public class EventDemoActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

android.util.Log.e(getClass().getSimpleName(), Integer.toHexString(hashCode()));

if (getFragmentManager().findFragmentById(android.R.id.content) == null) {
getFragmentManager().beginTransaction()
if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content,
new EventLogFragment()).commit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package com.commonsware.android.alarmclock;

import android.annotation.SuppressLint;
import android.app.ListFragment;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
Expand Down
12 changes: 6 additions & 6 deletions AlarmManager/AntiDoze/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ apply plugin: 'com.android.application'

dependencies {
implementation 'org.greenrobot:eventbus:3.0.0'
implementation 'com.android.support:support-compat:26.1.0'
implementation "com.android.support:support-v13:27.0.2"
}

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 19
targetSdkVersion 26
defaultConfig {
minSdkVersion 15
targetSdkVersion 27
}

flavorDimensions "default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

package com.commonsware.android.antidoze;

import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;

public class EventDemoActivity extends Activity {
public class EventDemoActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -40,8 +40,8 @@ public void onCreate(Bundle savedInstanceState) {
}
}

if (getFragmentManager().findFragmentById(android.R.id.content)==null) {
getFragmentManager().beginTransaction()
if (getSupportFragmentManager().findFragmentById(android.R.id.content)==null) {
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content,
new EventLogFragment()).commit();
startService(new Intent(this, ScheduledService.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package com.commonsware.android.antidoze;

import android.annotation.SuppressLint;
import android.app.ListFragment;
import android.support.v4.app.ListFragment;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
Expand Down
12 changes: 6 additions & 6 deletions Internet/CA/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ def WARES='"https://wares.commonsware.com/excerpt-7p0.pdf"'
def SELFSIGNED='"https://scrap.commonsware.com:3001/excerpt-7p0.pdf"'

android {
compileSdkVersion 24
buildToolsVersion '26.0.2'
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 17
targetSdkVersion 24
targetSdkVersion 27
}

flavorDimensions "default"
Expand Down Expand Up @@ -81,7 +81,7 @@ repositories {
}

dependencies {
implementation 'com.android.support:support-v13:24.2.0'
implementation 'com.commonsware.cwac:provider:0.4.4'
implementation 'com.commonsware.cwac:netsecurity:0.2.0'
implementation 'com.android.support:support-v13:27.0.2'
implementation 'com.commonsware.cwac:provider:0.5.3'
implementation 'com.commonsware.cwac:netsecurity:0.4.4'
}
4 changes: 3 additions & 1 deletion Internet/CA/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
</intent-filter>
</activity>

<service android:name="Downloader" />
<service
android:name="Downloader"
android:permission="android.permission.BIND_JOB_SERVICE" />

<provider
android:name="LegacyCompatFileProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@

package com.commonsware.android.downloader;

import android.app.Fragment;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v13.app.FragmentCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -39,7 +38,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
View result=inflater.inflate(R.layout.main, parent, false);

b=(Button)result.findViewById(R.id.button);
b=result.findViewById(R.id.button);
b.setOnClickListener(this);

return(result);
Expand All @@ -51,7 +50,7 @@ public void onClick(View v) {
doTheDownload();
}
else {
FragmentCompat.requestPermissions(this, PERMS_ALL, REQUEST_ALL);
requestPermissions(PERMS_ALL, REQUEST_ALL);
}
}

Expand All @@ -70,7 +69,7 @@ private void doTheDownload() {
Intent i=new Intent(getActivity(), Downloader.class);

i.setData(Uri.parse(BuildConfig.URL));
getActivity().startService(i);
Downloader.enqueueWork(getActivity(), i);
getActivity().finish();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,43 @@

package com.commonsware.android.downloader;

import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.JobIntentService;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.FileProvider;
import android.util.Log;
import com.commonsware.cwac.netsecurity.TrustManagerBuilder;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class Downloader extends IntentService {
public class Downloader extends JobIntentService {
private static final String AUTHORITY=
BuildConfig.APPLICATION_ID+".provider";
private static int NOTIFY_ID=1337;
private static int FOREGROUND_ID=1338;
private static int UNIQUE_JOB_ID=1339;
private static final String CHANNEL_WHATEVER="channel_whatever";

public Downloader() {
super("Downloader");
static void enqueueWork(Context ctxt, Intent i) {
enqueueWork(ctxt, Downloader.class, UNIQUE_JOB_ID, i);
}

@Override
public void onHandleIntent(Intent i) {
public void onHandleWork(Intent i) {
File output=new File(getFilesDir(),
i.getData().getLastPathSegment());

startForeground(FOREGROUND_ID,
buildForegroundNotification(output.getName()));

try {
if (output.exists()) {
output.delete();
Expand Down Expand Up @@ -99,8 +100,18 @@ public void onHandleIntent(Intent i) {

private void raiseNotification(String mimeType, File output,
Exception e) {
NotificationManager mgr=
(NotificationManager)getSystemService(
NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O &&
mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) {
mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER,
"Whatever", NotificationManager.IMPORTANCE_DEFAULT));
}

NotificationCompat.Builder b=
new NotificationCompat.Builder(this);
new NotificationCompat.Builder(this, CHANNEL_WHATEVER);

b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL);

Expand All @@ -127,23 +138,6 @@ private void raiseNotification(String mimeType, File output,
.setTicker(getString(R.string.exception));
}

NotificationManager mgr=
(NotificationManager)getSystemService(
NOTIFICATION_SERVICE);

mgr.notify(NOTIFY_ID, b.build());
}

private Notification buildForegroundNotification(String filename) {
NotificationCompat.Builder b=new NotificationCompat.Builder(this);

b.setOngoing(true);

b.setContentTitle(getString(R.string.downloading))
.setContentText(filename)
.setSmallIcon(android.R.drawable.stat_sys_download)
.setTicker(getString(R.string.downloading));

return(b.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

package com.commonsware.android.downloader;

import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

public class DownloaderDemo extends Activity {
public class DownloaderDemo extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (getFragmentManager().findFragmentById(android.R.id.content) == null) {
getFragmentManager().beginTransaction()
if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content,
new DownloadFragment()).commit();
}
Expand Down
9 changes: 7 additions & 2 deletions Rx/Retrofit/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ dependencies {
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation ("com.android.support:support-v4:27.0.2") {
exclude group: 'com.android.support', module: 'support-media-compat'
} // for https://issuetracker.google.com/issues/64909326
implementation 'io.reactivex.rxjava2:rxjava:2.1.7'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
}

android {
compileSdkVersion 25
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 15
targetSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"
applicationId "com.commonsware.android.rx.retrofit"
Expand Down
Loading

0 comments on commit d835daf

Please sign in to comment.