From 2ee09ae5505bff0ff64a5119475674dc2d9a9ed6 Mon Sep 17 00:00:00 2001 From: Patternoid Date: Fri, 4 Aug 2017 07:23:41 +0900 Subject: [PATCH] *#22 SettingsActivity Class Convert --- .../minimaltodo/SettingsActivity.java | 63 ------------------ .../minimaltodo/SettingsActivity.kt | 65 +++++++++++++++++++ 2 files changed, 65 insertions(+), 63 deletions(-) delete mode 100644 app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsActivity.java create mode 100644 app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsActivity.kt diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsActivity.java b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsActivity.java deleted file mode 100644 index a5e8b55..0000000 --- a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsActivity.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.example.avjindersinghsekhon.minimaltodo; - -import android.app.FragmentManager; -import android.graphics.Color; -import android.graphics.PorterDuff; -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import android.support.v4.app.NavUtils; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.MenuItem; - -public class SettingsActivity extends AppCompatActivity{ - - @Override - protected void onResume() { - super.onResume(); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - - String theme = getSharedPreferences(MainActivity.THEME_PREFERENCES, MODE_PRIVATE).getString(MainActivity.THEME_SAVED, MainActivity.LIGHTTHEME); - if(theme.equals(MainActivity.LIGHTTHEME)){ - setTheme(R.style.CustomStyle_LightTheme); - } - else{ - setTheme(R.style.CustomStyle_DarkTheme); - } - super.onCreate(savedInstanceState); -// getSupportActionBar().setDisplayHomeAsUpEnabled(true); - setContentView(R.layout.activity_settings); - Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - - final Drawable backArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_material); - if(backArrow!=null){ - backArrow.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP); - - } - - if(getSupportActionBar()!=null){ - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setHomeAsUpIndicator(backArrow); - } - - FragmentManager fm= getFragmentManager(); - fm.beginTransaction().replace(R.id.mycontent, new SettingsFragment()).commit(); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch(item.getItemId()){ - case android.R.id.home: - if(NavUtils.getParentActivityName(this)!=null){ - NavUtils.navigateUpFromSameTask(this); - } - return true; - default: - return super.onOptionsItemSelected(item); - } - } -} diff --git a/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsActivity.kt b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsActivity.kt new file mode 100644 index 0000000..3fe27d3 --- /dev/null +++ b/app/src/main/java/com/example/avjindersinghsekhon/minimaltodo/SettingsActivity.kt @@ -0,0 +1,65 @@ +package com.example.avjindersinghsekhon.minimaltodo + +import android.app.FragmentManager +import android.graphics.Color +import android.graphics.PorterDuff +import android.graphics.drawable.Drawable +import android.os.Bundle +import android.os.PersistableBundle +import android.support.v4.app.NavUtils +import android.support.v7.app.AppCompatActivity +import android.view.MenuItem +import kotlinx.android.synthetic.main.activity_settings.* + +/** + * Created by patternoid on 2017. 8. 4.. + */ +class SettingsActivity : AppCompatActivity() { + + override fun onResume() { + super.onResume() + } + + + override fun onCreate(savedInstanceState: Bundle?) { + + val theme : String = getSharedPreferences(MainActivity.THEME_PREFERENCES, MODE_PRIVATE).getString(MainActivity.THEME_SAVED, MainActivity.LIGHTTHEME) + if(theme.equals(MainActivity.LIGHTTHEME)){ + setTheme(R.style.CustomStyle_LightTheme) + }else{ + setTheme(R.style.CustomStyle_DarkTheme) + } + + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_settings) + setSupportActionBar(toolbar) + + val backArrow : Drawable? = resources.getDrawable(R.drawable.abc_ic_ab_back_material) + backArrow?.let{ + backArrow.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP) + } + + supportActionBar?.apply { + setDisplayHomeAsUpEnabled(true) + setHomeAsUpIndicator(backArrow) + } + + fragmentManager.beginTransaction().replace( + R.id.mycontent, + SettingsFragment() + ).commit() + } + + + override fun onOptionsItemSelected(item: MenuItem?): Boolean { + when( item?.itemId ){ + android.R.id.home -> { + NavUtils.getParentActivityName(this@SettingsActivity)?.let{ + NavUtils.navigateUpFromSameTask(this@SettingsActivity) + } + return true + } + else -> return super.onOptionsItemSelected(item) + } + } +} \ No newline at end of file