Skip to content

Commit

Permalink
a few more onboarding and permissions tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Oct 30, 2017
1 parent 6a867f5 commit 91227e7
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 20 deletions.
74 changes: 67 additions & 7 deletions src/main/java/info/guardianproject/phoneypot/MonitorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
*/
package info.guardianproject.phoneypot;

import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Camera;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.text.InputType;
import android.util.Log;
import android.view.DragEvent;
Expand Down Expand Up @@ -57,9 +61,17 @@ public class MonitorActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

preferences = new PreferenceManager(getApplicationContext());
super.onCreate(savedInstanceState);

boolean permsNeeded = askForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, 1);

if (!permsNeeded)
initLayout();
}

private void initLayout ()
{
preferences = new PreferenceManager(getApplicationContext());
setContentView(R.layout.layout_running);

txtTimer = (TextView)findViewById(R.id.timer_text);
Expand All @@ -79,6 +91,14 @@ public void onClick(View v) {

}
});
findViewById(R.id.timer_text_title).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (cTimer == null)
showNumberPicker();

}
});

findViewById(R.id.btnStartLater).setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -111,7 +131,9 @@ public void onClick(View v) {
}
});

}


}

private void switchCamera ()
{
Expand Down Expand Up @@ -236,9 +258,11 @@ private void initMonitor ()
private void close() {

stopService(new Intent(this, MonitorService.class));
preferences.unsetAccessToken();
preferences.unsetDelegatedAccessToken();
preferences.unsetPhoneId();
if (preferences != null) {
preferences.unsetAccessToken();
preferences.unsetDelegatedAccessToken();
preferences.unsetPhoneId();
}
finish();

}
Expand Down Expand Up @@ -277,4 +301,40 @@ public void onClick(DialogInterface dialogInterface, int i) {
.show();
}

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

switch (requestCode) {
case 1:
askForPermission(Manifest.permission.CAMERA,2);
break;
case 2:
initLayout();
break;
}

}


private boolean askForPermission(String permission, Integer requestCode) {
if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {

// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {

//This is called if user has denied the permission before
//In this case I am just asking the permission again
ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);

} else {

ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);
}
return true;
} else {
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CustomSlideNotify extends Fragment {
private static final String ARG_LAYOUT_RES_ID = "layoutResId";
private int layoutResId;
private EditText mEditNumber;

private View.OnClickListener mListener;
public static CustomSlideNotify newInstance(int layoutResId) {
CustomSlideNotify sampleSlide = new CustomSlideNotify();

Expand All @@ -41,6 +41,11 @@ public static CustomSlideNotify newInstance(int layoutResId) {
return sampleSlide;
}

public void setSaveListener (View.OnClickListener listener)
{
mListener = listener;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -70,22 +75,14 @@ public void onClick(View v) {
mEditNumber.setText(pm.getSmsNumber());

Button button = (Button)view.findViewById(R.id.btnSaveNumber);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveNumber();
}
});
button.setOnClickListener(mListener);
return view;

}

private void saveNumber ()
public String getPhoneNumber ()
{
PreferenceManager pm = new PreferenceManager(getActivity());
pm.activateSms(true);
pm.setSmsNumber(mEditNumber.getText().toString());
Toast.makeText(getActivity(),"Phone number saved!",Toast.LENGTH_SHORT).show();
return mEditNumber.getText().toString();
}

private void askForPermission(String permission, Integer requestCode) {
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/info/guardianproject/phoneypot/ui/PPAppIntro.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.Toast;


import info.guardianproject.phoneypot.PreferenceManager;
import info.guardianproject.phoneypot.R;

/**
Expand Down Expand Up @@ -53,7 +55,17 @@ public void onClick(View v) {
cs3.setTitle(getString(R.string.intro4_desc));
addSlide(cs3);

CustomSlideNotify cs4 = CustomSlideNotify.newInstance(R.layout.custom_slide_notify);
final CustomSlideNotify cs4 = CustomSlideNotify.newInstance(R.layout.custom_slide_notify);
cs4.setSaveListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PreferenceManager pm = new PreferenceManager(PPAppIntro.this);
pm.activateSms(true);
pm.setSmsNumber(cs4.getPhoneNumber());
Toast.makeText(PPAppIntro.this,"Phone number saved!",Toast.LENGTH_SHORT).show();
getPager().setCurrentItem(getPager().getCurrentItem()+1);
}
});
addSlide(cs4);

addSlide(AppIntroFragment.newInstance(getString(R.string.intro5_title), getString(R.string.intro5_desc),
Expand Down

0 comments on commit 91227e7

Please sign in to comment.