Skip to content

Commit

Permalink
Shared Preferences & RESET
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyro9922 committed Oct 27, 2018
1 parent 9a39d5a commit 6e6c094
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 13 deletions.
66 changes: 66 additions & 0 deletions AndroidHack/.idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions AndroidHack/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".GearActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service android:name="org.eclipse.paho.android.service.MqttService">
</service>
<service android:name="org.eclipse.paho.android.service.MqttService"></service>

<!--Receiver Service-->
<service android:name=".ReceiverService"
android:enabled="true"/>
<!-- Receiver Service -->
<service
android:name=".ReceiverService"
android:enabled="true" />

<activity android:name=".SelectTime"></activity>
<activity android:name=".SelectTime" />
<activity android:name=".MainActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.alihasan.androidhack;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class GearActivity extends AppCompatActivity {

TextView timeView;
TextView phoneView;

ImageView gearIcon;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gear);

timeView = findViewById(R.id.timeView);
phoneView = findViewById(R.id.phoneView);

gearIcon = findViewById(R.id.gearIcon);


}


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
public class MainActivity extends AppCompatActivity {

NumberPicker np;

EditText Phone1;
EditText Phone2;
EditText Phone3;


Button next;

@Override
Expand All @@ -21,11 +26,15 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

np = findViewById(R.id.np);

Phone1 = findViewById(R.id.Phone1);
Phone2 = findViewById(R.id.Phone2);
Phone3 = findViewById(R.id.Phone3);

next = findViewById(R.id.next);

np.setMinValue(0);
np.setMaxValue(1);
np.setMaxValue(3);

np.setWrapSelectorWheel(true);

Expand All @@ -37,8 +46,12 @@ public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
{
case 1:
Phone1.setVisibility(View.VISIBLE);
case 2:
Phone2.setVisibility(View.VISIBLE);
case 3:
Phone3.setVisibility(View.VISIBLE);
default:
Toast.makeText(MainActivity.this, "Only "+newVal+" Participant", Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "Only "+newVal+" Participants :) !!!", Toast.LENGTH_SHORT).show();

}
}
Expand All @@ -55,6 +68,18 @@ public void onClick(View v) {
* IN SHARED PREFERENCE
*/

SharedPrefClass storeMobile1 = new SharedPrefClass(MainActivity.this);
storeMobile1.saveMobile("mobile1 : ", Phone1.getText().toString());

SharedPrefClass storeMobile2 = new SharedPrefClass(MainActivity.this);
storeMobile2.saveMobile("mobile2 : ", Phone2.getText().toString());

SharedPrefClass storeMobile3 = new SharedPrefClass(MainActivity.this);
storeMobile3.saveMobile("mobile3 : ", Phone3.getText().toString());

//GET PHONE FROM HERE
// new SharedPrefClass(MainActivity.this).getMobile("mobile1 : ");

}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
package com.example.alihasan.androidhack;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPrefClass {

Context context;
String timings;
String mobile;

public SharedPrefClass(Context context1, String timings1){
public SharedPrefClass(Context context1){

context = context1;
timings = timings1;
// mobile = mobile1;

}

public void saveMobile(String code, String mobile1){

mobile = mobile1;

}
SharedPreferences sharedPref = context.getSharedPreferences("mobile", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString(code, mobile);
editor.commit();
}

public String getMobile(String code){

SharedPreferences sharedPref = context.getSharedPreferences("mobile", Context.MODE_PRIVATE);
String timingValue = sharedPref.getString(code, "-1");

return timingValue;
}




}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions AndroidHack/app/src/main/res/layout/activity_gear.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".GearActivity">

<TextView
android:id="@+id/timeView"
android:hint="Time"
android:textSize="30sp"
android:lines="4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<ImageView
android:id="@+id/gearIcon"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@drawable/ic_action_name"
android:onClick="gearClicked"/>

<TextView
android:id="@+id/phoneView"
android:hint="Phone"
android:textSize="30sp"
android:lines="4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>
16 changes: 16 additions & 0 deletions AndroidHack/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,20 @@
android:layout_height="wrap_content"
android:visibility="gone"/>

<EditText
android:id="@+id/Phone2"
android:textSize="25sp"
android:hint="Enter phone no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>

<EditText
android:id="@+id/Phone3"
android:textSize="25sp"
android:hint="Enter phone no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>

</LinearLayout>

0 comments on commit 6e6c094

Please sign in to comment.