Skip to content
Snippets Groups Projects
Commit 86bb2489 authored by Rizki Halasan's avatar Rizki Halasan
Browse files

add setting menu

parent 549de890
Branches
No related merge requests found
......@@ -21,9 +21,9 @@
android:hardwareAccelerated="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:largeHeap="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
......@@ -56,7 +56,8 @@
<activity
android:name=".JoggingActivity"
android:label="@string/title_activity_jogging"></activity>
android:label="@string/title_activity_jogging" />
<activity android:name=".SettingActivity"></activity>
</application>
</manifest>
\ No newline at end of file
package com.example.leo.fitnessdiy;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
......@@ -16,11 +21,28 @@ public class HomeActivity extends AppCompatActivity
BlankFragment.OnFragmentInteractionListener{
private FloatingActionButton chatButton;
private SharedPreferences mPreferences;
private String sharedPrefFile = "com.example.leo.fitnessdiy";
private final String BACKGROUND_KEY = "background";
private final String LOG_TAG = "MAIN ACTIVITY";
@Override
public void onFragmentInteraction(Uri uri) {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.setting_menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.menu_setting_background) {
Intent i = new Intent(this, SettingActivity.class);
startActivity(i);
}
return true;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -28,6 +50,17 @@ public class HomeActivity extends AppCompatActivity
setContentView(R.layout.activity_home);
chatButton = findViewById(R.id.chat_button);
chatButton.setImageResource(R.drawable.chat_icon);
mPreferences = getSharedPreferences(sharedPrefFile, MODE_PRIVATE);
SharedPreferences.Editor preferencesEditor = mPreferences.edit();
preferencesEditor.putInt(BACKGROUND_KEY, R.drawable.green_theme);
preferencesEditor.apply();
// mPreferences = getSharedPreferences(sharedPrefFile, MODE_PRIVATE);
// int background = mPreferences.getInt(BACKGROUND_KEY, R.drawable.green_theme);
// getWindow().getDecorView().setBackground(getResources().getDrawable(R.drawable.green_theme));
// Log.d(LOG_TAG, ""+background);
}
public void openHistory(View view) {
......@@ -39,12 +72,6 @@ public class HomeActivity extends AppCompatActivity
public void changeFragment(View view){
Fragment fragment;
// fragment = getSupportFragmentManager().findFragmentById(R.id.home_fragment);
// FragmentManager manager = getSupportFragmentManager();
// if (fragment != null) {
// getSupportFragmentManager().beginTransaction().remove(fragment).commit();
// manager.popBackStack();
// }
if(view == findViewById(R.id.history_button)){
fragment = new HistoryFragment();
......@@ -73,4 +100,6 @@ public class HomeActivity extends AppCompatActivity
Intent i = new Intent(getApplicationContext(), ChatActivity.class);
startActivity(i);
}
}
package com.example.leo.fitnessdiy;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toolbar;
public class MainActivity extends AppCompatActivity {
......
package com.example.leo.fitnessdiy;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class SettingActivity extends AppCompatActivity {
private String LOG_TAG = "SETTING ACTIVITY";
private String sharedPrefFile = "com.example.leo.fitnessdiy";
private final String BACKGROUND_KEY = "background";
private SharedPreferences mPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
}
public void changeBackgroundColor(View view) {
int background = 0;
if(view.getId() == R.id.green_theme){
background = R.drawable.green_theme;
}
if(view.getId() == R.id.red_theme){
background = R.drawable.red_theme;
}
Log.d(LOG_TAG, ""+background);
Log.d(LOG_TAG, "tes");
mPreferences = getSharedPreferences(sharedPrefFile, MODE_PRIVATE);
SharedPreferences.Editor preferencesEditor = mPreferences.edit();
preferencesEditor.putInt(BACKGROUND_KEY, background);
preferencesEditor.apply();
Intent i = new Intent(this, HomeActivity.class);
startActivity(i);
}
}
app/src/main/res/drawable/green_theme.jpg

123 KiB

app/src/main/res/drawable/red_theme.jpg

324 KiB

<?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"
tools:context="com.example.leo.fitnessdiy.SettingActivity"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="32sp"
android:layout_marginBottom="20dp"
android:textColor="@android:color/black"
android:text="Select Background Color"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/green_theme"
android:text="green_theme"
android:textSize="20sp"
android:layout_margin="6dp"
android:onClick="changeBackgroundColor"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/red_theme"
android:text="red_theme"
android:textSize="20sp"
android:layout_margin="6dp"
android:onClick="changeBackgroundColor"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="Background"
app:showAsAction="never"
android:id="@+id/menu_setting_background"/>
</menu>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment