Skip to content

Commit

Permalink
update for Marshmallow permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
daktak committed Mar 2, 2016
1 parent f9fe566 commit 1693e0e
Show file tree
Hide file tree
Showing 12 changed files with 504 additions and 244 deletions.
Binary file modified .gradle/2.8/taskArtifacts/cache.properties.lock
Binary file not shown.
Binary file modified .gradle/2.8/taskArtifacts/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/2.8/taskArtifacts/fileSnapshots.bin
Binary file not shown.
Binary file modified .gradle/2.8/taskArtifacts/taskArtifacts.bin
Binary file not shown.
313 changes: 102 additions & 211 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 19
targetSdkVersion 23
versionCode 20160302
versionName "0.5.4"
versionName "0.5.5"
}
buildTypes {
release {
Expand Down
95 changes: 63 additions & 32 deletions app/src/main/java/org/androidpn/client/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,40 @@

import org.androidpn.client.SerivceManager.LogUtil;
import org.androidpn.client.SerivceManager.ServiceManager;
import org.androidpn.client.helper.EasyPermissions;
import org.androidpn.client.helper.SwipeDismissListViewTouchListener;
import org.androidpn.client.helper.fixTheme;

import android.Manifest;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
import java.util.List;

public class MainActivity extends AppCompatActivity
implements EasyPermissions.PermissionCallbacks {
// implements AdapterView.OnItemClickListener {

public static MainActivity instance = null;
private static final int REQUEST_PREFS = 1;
private ServiceManager serviceManager;
SimpleCursorAdapter dataAdapter;
PNNotificationDataSource datasource;
private int RC_PHONE_STATE = 1;

private static final String LOGTAG = LogUtil
.makeLogTag(MainActivity.class);
String[] perms = { Manifest.permission.READ_PHONE_STATE };

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -41,6 +46,17 @@ protected void onCreate(Bundle savedInstanceState) {
setSupportActionBar(toolbar);
PreferenceManager.setDefaultValues(this, R.xml.settings, false);

if (EasyPermissions.hasPermissions(this, perms)) {
// Have permissions, do the thing!
set();
} else {
// Ask for both permissions
EasyPermissions.requestPermissions(this, getString(R.string.rationale_phone_state),
RC_PHONE_STATE, perms);
}
}

public void set(){
resetList();

SharedPreferences mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
Expand Down Expand Up @@ -135,23 +151,10 @@ public void onDismiss(ListView listView, int[] reverseSortedPositions) {
}
});
notifyList.setOnTouchListener(touchListener);
notifyList.setOnItemClickListener(this);
onClickListener ocl = new onClickListener(this, dataAdapter, datasource);
notifyList.setOnItemClickListener(ocl);
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String uri = datasource.cursorTonotification((Cursor) dataAdapter.getItem(position)).getUri();
if (uri != null && uri.length() > 0) {
Intent intent = new Intent(Intent.ACTION_VIEW);
try {
intent.setData(Uri.parse(uri));
startActivity(intent);
} catch (Exception e) {
Log.w(LOGTAG,e.toString());
}

}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
Expand All @@ -176,7 +179,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (id == R.id.action_clear) {
datasource.open();
datasource.deleteAllNotifications();
dataAdapter.notifyDataSetChanged();
// dataAdapter.notifyDataSetChanged();
datasource.close();
resetList();
}
Expand All @@ -199,19 +202,20 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
startActivity(getIntent());
}
// loadPref();

if (serviceManager != null) {

if (serviceManager.isNewSettings(this)) {
Log.d(LOGTAG, "Restarting sm");
serviceManager.stopService();
serviceManager.setSettings();
if (EasyPermissions.hasPermissions(this, perms)) {
if (serviceManager != null) {

if (serviceManager.isNewSettings(this)) {
Log.d(LOGTAG, "Restarting sm");
serviceManager.stopService();
serviceManager.setSettings();
serviceManager.startService();
}
} else {
serviceManager = new ServiceManager(this);
serviceManager.setNotificationIcon(R.drawable.notification);
serviceManager.startService();
}
} else {
serviceManager = new ServiceManager(this);
serviceManager.setNotificationIcon(R.drawable.notification);
serviceManager.startService();
}
}

Expand All @@ -220,7 +224,13 @@ protected void onResume() {
boolean reset = fixTheme.fixTheme(this);
super.onResume();
instance = this;
resetList();
if (EasyPermissions.hasPermissions(this, perms)) {
resetList();
} else {
// Ask for both permissions
EasyPermissions.requestPermissions(this, getString(R.string.rationale_phone_state),
RC_PHONE_STATE, perms);
}
}

@Override
Expand All @@ -229,4 +239,25 @@ protected void onPause() {
instance = null;
}


@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

// Forward results to EasyPermissions
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}

@Override
public void onPermissionsGranted(int requestCode, List<String> list) {
// Some permissions have been granted
set();
}

@Override
public void onPermissionsDenied(int requestCode, List<String> list) {
// Some permissions have been denied

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public ServiceManager(Context context) {
}
setSettings();
}

public void setSettings() {

// apiKey = getMetaDataValue("ANDROIDPN_API_KEY");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.androidpn.client.helper;

/*
* Copyright Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AfterPermissionGranted {

int value();

}
Loading

0 comments on commit 1693e0e

Please sign in to comment.