Skip to content

Commit

Permalink
code formatting and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek0706 committed Dec 21, 2019
1 parent a5e9250 commit 9a13f60
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.example.secretlocklibrary;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.example.secretlock.SecretLock;

public class MainActivity extends AppCompatActivity {
Expand Down
60 changes: 28 additions & 32 deletions secretlock/src/main/java/com/example/secretlock/SecretLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.LocationManager;
import android.media.AudioManager;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.util.Log;
import android.widget.Toast;

import com.example.secretlock.adapters.ItemAdapter;
import com.example.secretlock.models.Item;
Expand All @@ -21,8 +17,9 @@

public class SecretLock {


/// Get settings value that is stored in shared preferences
private HashMap<String, Boolean> getPreferenceValues(Context context) {

SharedPreferences pref = context.getSharedPreferences("system_settings", MODE_PRIVATE);
boolean p_wifi = pref.getBoolean("wifi_status", false);
boolean p_bluetooth = pref.getBoolean("bluetooth_status", false);
Expand All @@ -37,49 +34,49 @@ private HashMap<String, Boolean> getPreferenceValues(Context context) {
_map.put("bluetooth_status", p_bluetooth);
_map.put("airplanemode_status", p_airplane);
_map.put("ring_status", p_ring);
// _map.put("vibrate_status", p_vibrate);
_map.put("gps_status", p_gps);
_map.put("rotate_status", p_rotate);
// _map.put("vibrate_status", p_vibrate);

return _map;

}

/// Get current value of system settings
private HashMap<String, Boolean> getSystemValues(Context context) {

boolean bluetooth_status = false;
boolean airplanemode_status = false;
boolean ring_status = false;
boolean wifi_status = false;
// boolean vibrate_status = false;
boolean gps_status = false;
boolean rotate_status = false;
boolean bluetooth_status = false;/// bluetooth is on/off
boolean airplanemode_status = false;///airplane mode on/off
boolean ring_status = false;///ring profile on/off (off when silent)
boolean wifi_status = false;///wifi is on/off
boolean gps_status = false;///gps is on/off
boolean rotate_status = false;///auto rotate is on/off
// boolean vibrate_status = false;///vibration is on/off

/// wifi status
wifi_status = getBoolean(Integer.parseInt(Settings.System.getString(context.getContentResolver(), Settings.System.WIFI_ON)));

/// bluetooth status
bluetooth_status = getBoolean(Integer.parseInt(Settings.System.getString(context.getContentResolver(), Settings.System.BLUETOOTH_ON)));

/// airplane mode status
airplanemode_status = getBoolean(Integer.parseInt(Settings.System.getString(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON)));

// Toast.makeText(context, Settings.System.getString(context.getContentResolver(), Settings.System.VIBRATE_ON), Toast.LENGTH_LONG).show();
// vibrate_status = getBoolean(Integer.parseInt(Settings.System.getString(context.getContentResolver(), Settings.System.VIBRATE_ON)));

/// ring status
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (audioManager != null) {
ring_status = getBoolean(audioManager.getStreamVolume(AudioManager.STREAM_RING));// zero when mute

}

// WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
// if (wifiManager != null) {
// wifi_status = wifiManager.isWifiEnabled();
//
// }

/// gps status
final LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (locationManager != null) {
gps_status = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}


/// auto rotate status
rotate_status = getBoolean(android.provider.Settings.System.getInt(context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0));


Expand All @@ -88,14 +85,15 @@ private HashMap<String, Boolean> getSystemValues(Context context) {
_map.put("bluetooth_status", bluetooth_status);
_map.put("airplanemode_status", airplanemode_status);
_map.put("ring_status", ring_status);
// _map.put("vibrate_status", vibrate_status);
_map.put("gps_status", gps_status);
_map.put("rotate_status", rotate_status);
// _map.put("vibrate_status", vibrate_status);

return _map;

}

/// Set setting values in the shared preference
public void setPreferenceValues(Context context, HashMap<String, Boolean> _map) {
SharedPreferences pref = context.getSharedPreferences("system_settings", MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
Expand All @@ -111,17 +109,15 @@ public void setPreferenceValues(Context context, HashMap<String, Boolean> _map)
if (_map.containsKey("ring_status")) {
editor.putBoolean("ring_status", _map.get("ring_status"));
}
// if (_map.containsKey("vibrate_status")) {
// editor.putBoolean("vibrate_status", _map.get("vibrate_status"));
// }

if (_map.containsKey("gps_status")) {
editor.putBoolean("gps_status", _map.get("gps_status"));
}
if (_map.containsKey("rotate_status")) {
editor.putBoolean("rotate_status", _map.get("rotate_status"));
}

// if (_map.containsKey("vibrate_status")) {
// editor.putBoolean("vibrate_status", _map.get("vibrate_status"));
// }

editor.apply();

Expand All @@ -132,18 +128,18 @@ private boolean getBoolean(int a) {
return a != 0;
}


/// Return the lock is ON or OFF
public boolean getLockValue(Context context) {

HashMap<String, Boolean> preference = getPreferenceValues(context);
HashMap<String, Boolean> system = getSystemValues(context);

// Toast.makeText(context, preference.toString(), Toast.LENGTH_SHORT).show();
// Toast.makeText(context, system.toString(), Toast.LENGTH_SHORT).show();

return preference.equals(system);

}

/// Open Alert Dialog which change the preference settings
public void openSettings(final Context context) {

ArrayList<Item> itemList = new ArrayList<Item>();
Expand All @@ -156,9 +152,9 @@ public void openSettings(final Context context) {
itemList.add(new Item("bluetooth_status", preference.get("bluetooth_status")));
itemList.add(new Item("airplanemode_status", preference.get("airplanemode_status")));
itemList.add(new Item("ring_status", preference.get("ring_status")));
// itemList.add(new Item("vibrate_status", preference.get("vibrate_status")));
itemList.add(new Item("gps_status", preference.get("gps_status")));
itemList.add(new Item("rotate_status", preference.get("rotate_status")));
// itemList.add(new Item("vibrate_status", preference.get("vibrate_status")));

final ItemAdapter adapter = new ItemAdapter(context, itemList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void setValue(Boolean value) {
this.value = value;
}

/// Name that will be shown on Alert Dialog
public String getXmlName() {
return name_map.get(this.name);
}
Expand Down

0 comments on commit 9a13f60

Please sign in to comment.