Saturday, July 22, 2017

Butter Knife

  No comments
6:18 AM


Info
Category : Free
Link : http://jakewharton.github.io/butterknife

Description
Field and method binding for Android views which uses annotation processing to generate boilerplate code for you.
  • Eliminate findViewById calls by using @BindView on fields.
  • Group multiple views in a list or array. Operate on all of them at once with actions, setters, or properties.
  • Eliminate anonymous inner-classes for listeners by annotating methods with @OnClick and others.
  • Eliminate resource lookups by using resource annotations on fields.

Introduction
In every Android application, you have to use the findViewById() method for each view in the layout that you want to use in your application's code. But as applications' designs get more complex layouts, the call to this method becomes repetitive and this is where the Butter Knife library comes in.

The Butter Knife library, developer and maintained by Jake Wharton (Square Inc.), has annotations that help developers to instantiate the views from our activity or fragment. It also has annotations to handle events like onClick(), onLongClick(), etc.

In the sample project of this tutorial, you can see a sample application with one activity and one fragment with an implementation using the Butter Knife library and a regular implementation. Let's explore the steps involved to integrate the Butter Knife library.

Using the Butter Knife
  1. Add the following dependency to the project's build.gradle file:
    compile 'com.jakewharton:butterknife:8.7.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
    
  2. Synchronize your project with this file by pressing the synchronize button.
  3. Use the Annotations
    In every activity or fragment, you have to remove, or comment out, every call of the findViewById() method and add the @BindView annotation before the declaration of the variable, indicating the identifier of the view.
    @BindView(R.id.user) EditText username;
    @BindView(R.id.pass) EditText password;
  4. Inject Views
    In the onCreate() method of the activity, before using any the views, call inject on the Butterknife object.
    ButterKnife.bind(this);
    
    If you are using fragments, you have to specify the source of the views in the onCreateView() method as shown below.
    View view = inflater.inflate(R.layout.sample_fragment, null);
    ButterKnife.bind(this, view);
    
    You can now start using the views in your application's code. Butter Knife will handle the instantiation of every single view for you.
    That is all you have to do to use the Butter Knife library in an activity or fragment.

Proguard Rules
-keep public class * implements butterknife.Unbinder { public <init>(**, android.view.View); }
# Prevent obfuscation of types which use ButterKnife annotations since the simple name
# is used to reflectively look up the generated ViewBinding.
-keep class butterknife.*
-keepclasseswithmembernames class * { @butterknife.* <methods>; }
-keepclasseswithmembernames class * { @butterknife.* <fields>; }

Read More

Friday, October 21, 2016

[CUSTOM ROM] MIUI8 Lenovo S90

  1 comment

Monday, October 17, 2016

[SOURCE CODE] PreferenceFragment dengan Tab dan ViewPager

  No comments
6:35 AM


  1. Import Unofficial PreferenceFragment dari https://github.com/Machinarius/PreferenceFragment-Compat
  2. Buka layout activity_main.xml buat kodenya sebagai berikut :
    <?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:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:id="@+id/linearlayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            android:orientation="vertical">
    
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:contentInsetStart="16dp"/>
    
            <android.support.design.widget.TabLayout
                android:minHeight="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="40.0dp" />
        </LinearLayout>
    
        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:background="#80000000" />
    </LinearLayout>
    
  3. Buat resource file dengan resource type xml meliputi theme_settings.xml, color_settings.xml dan about_settings.xml.
  4. Buat class Fragment, banyaknya fragment tergantung berapa tab yang akan kita buat. Sebagai contoh saya menggunakan 3 tab, maka dari itu saya membuat 3 fragment, yaitu FragmentTema, FragmentWarna, FragmentTentang.
    - FragmentTema.java
    package id.delta.settings.fragment;
    
    import android.os.Bundle;
    
    import com.github.machinarius.preferencefragment.PreferenceFragment;
    
    import id.delta.settings.R;
    
    /**
     * Created by Administrator on 10/17/16.
     */
    
    public class FragmentTema extends PreferenceFragment {
        // PreferenceFragment di sini menggunakan PreferenceFragment yang dari https://github.com/Machinarius/PreferenceFragment-Compat
        @Override
        public void onCreate(Bundle paramBundle) {
            super.onCreate(paramBundle);
            addPreferencesFromResource(R.xml.theme_settings);
        }
    }
    

    - FragmentWarna.java
    package id.delta.settings.fragment;
    
    import android.os.Bundle;
    
    import com.github.machinarius.preferencefragment.PreferenceFragment;
    
    import id.delta.settings.R;
    
    /**
     * Created by Administrator on 10/17/16.
     */
    
    public class FragmentWarna extends PreferenceFragment {
        // PreferenceFragment di sini menggunakan PreferenceFragment yang dari https://github.com/Machinarius/PreferenceFragment-Compat
        @Override
        public void onCreate(Bundle paramBundle) {
            super.onCreate(paramBundle);
            addPreferencesFromResource(R.xml.color_settings);
        }
    }
    

    - FragmentTentang.java
    package id.delta.settings.fragment;
    
    import android.os.Bundle;
    
    import com.github.machinarius.preferencefragment.PreferenceFragment;
    
    import id.delta.settings.R;
    
    /**
     * Created by Administrator on 10/17/16.
     */
    
    public class FragmentTentang extends PreferenceFragment {
        // PreferenceFragment di sini menggunakan PreferenceFragment yang dari https://github.com/Machinarius/PreferenceFragment-Compat
        @Override
        public void onCreate(Bundle paramBundle) {
            super.onCreate(paramBundle);
            addPreferencesFromResource(R.xml.about_settings);
        }
    }
    
  5. Buat class baru dengan nama SettingsAdapter.java dengan isi kode sebagai berikut :
    package id.delta.settings.adapter;
    
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentStatePagerAdapter;
    
    import id.delta.settings.fragment.FragmentTema;
    import id.delta.settings.fragment.FragmentTentang;
    import id.delta.settings.fragment.FragmentWarna;
    
    /**
     * Created by Administrator on 10/17/16.
     */
    
    public class SettingsAdapter extends FragmentStatePagerAdapter {
    
        public SettingsAdapter(FragmentManager fragmentManager){
            super(fragmentManager);
        }
    
        @Override
        public Fragment getItem(int position) {
            Fragment fragment = null;
            switch (position){
                case 0:
                    fragment=new FragmentTema();
                    break;
                case 1:
                    fragment=new FragmentWarna();
                    break;
                case 2:
                    fragment=new FragmentTentang();
                    break;
            }
    
            return fragment;
        }
    
        @Override
        public int getCount() {
            return 3;
        }
    
        @Override
        public CharSequence getPageTitle(int position) {
            String title=" ";
            switch (position){
                case 0:
                    title="THEME";
                    break;
                case 1:
                    title="COLOR";
                    break;
                case 2:
                    title="ABOUT";
                    break;
            }
    
            return title;
        }
    }
    
  6. Buka MainActivity.java edit seperti berikut :
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            setupView();
        }
    
        void setupView(){
            //Toolbar
            Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
    
            //ViewPager
            ViewPager mPager = (ViewPager) findViewById(R.id.pager);
            mPager.setAdapter(new SettingsAdapter(getSupportFragmentManager()));
            mPager.setOffscreenPageLimit(3);
    
            //TabLayout
            TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
            tabs.setupWithViewPager(mPager);
        }
    }
    
  7. Isi xml theme_settings, color_settings dan about_settings sesuai dengan yang anda inginkan.

Read More

[FIRMWARE] Asus ZE500KG (Z00RD) Raw

  No comments

Wednesday, August 24, 2016

Upload Project ke GitHub

  No comments
11:43 PM

Assalamu'alaikum Teman, ini tutorial untuk mengunggah project kita ke GitHub.com. Saya tidak akan menjelaskan apa itu GitHub, langsung saja perhatikan prosesnya.

1. Buatlah akun di GitHub.com
2. Download dan install software Git di sini git-scm.com
3. Login ke Github.com dan buatlah sebuah repository baru dengan mengeklik tombol ( + ) yang terletak di atas sebelah kanan, dan pilih New Repository.
4. Isi Repository name dengan nama project anda.
5. Cek Initialize this repository with a README, kemudian pilih Create repository.
6. Sekarang kita bisa mengakses remote repository dengan url

https://github.com/DeltalabsProject/Change-Icon-Launcher-from-Preference.git

7. Untuk pengguna Windows klik kanan folder project dan pilih Git Bash. Berikut gambarnya:

8.Jika baru pertama kali meggunakan software Git, sebaiknya konfigurasi username dan email dulu
git config --global user.name "username anda"
git config --global user.email “email anda”
9. Setelah melakukan konfigurasi username dan email, kemudian lakukan inisiasi dengan menulis perintah berikut :
git init

10. Kemudian tambahkan semua file yang ada dalam folder project kita, ketikan
git add *

11. Buat commit projectnya, sebagai contoh disini commit “versi 1.0”
git commit –m "versi 1.0"

12. Setelah kita buat commit untuk projectnya, remote repository yang telah dibuat tadi
git remote add origin https://github.com/DeltalabsProject/Change-Icon-Launcher-from-Preference.git

13. Setelah meremote repository, kemudian kita pull projectnya dengan perintah
git pull origin master

14. Jika mengalami error
fatal: refusing to merge unrelated histories
lakukan perintah
git pull origin master --allow-unrelated-histories

15. Upload project ke repository kita
git push origin master

16. Terakhir, kita akan diminta username dan password kita. Untuk password mungkin kita tidak akan melihat password yang kita ketikan
17. Tunggu sampai project selesai di upload
18. Jika proses upload selesai, cek pada Github lalu refresh repository, maka file kita sudah terupload disana

Read More

Monday, August 22, 2016

[MOD] [BBM] Mengubah Bubble BBM

  No comments
2:01 AM


Assalamu'alaikum Teman, kali ini akan saya bagikan cara untuk mengganti bubble atau gelembung di BBM dengan berbagai style dan warnanya.

1. Buka values/colors.xml ganti kode warna jadi seperti di bawah :
    <color name="chat_bubble_incoming">#00000000</color>
    <color name="chat_bubble_incoming_0">#00000000</color>
    <color name="chat_bubble_incoming_1">#00000000</color>
    <color name="chat_bubble_incoming_2">#00000000</color>
    <color name="chat_bubble_incoming_3">#00000000</color>
    <color name="chat_bubble_incoming_4">#00000000</color>
    <color name="chat_bubble_incoming_5">#00000000</color>
    <color name="chat_bubble_incoming_6">#00000000</color>
    <color name="chat_bubble_incoming_7">#00000000</color>
    <color name="chat_bubble_incoming_8">#00000000</color>
    <color name="chat_bubble_incoming_9">#00000000</color>
    <color name="chat_bubble_outgoing">#00000000</color>
 
2. Buka values/arrays.xml tambahkan kode berikut di dalamnya.
    <string-array name="bubble_labels">
        <item>Default BBM</item>
        <item>Hike</item>
        <item>Material Design</item>
        <item>MeeGo Bubble Style</item>
        <item>MD Bubble Style</item>
        <item>Miui 6 Bubble Style</item>
        <item>Rounded</item>
        <item>Line</item>
        <item>Apple Bubble</item>
        <item>Windows Phone</item>
        <item>Chat On</item>
        <item>Telegram</item>
    </string-array>
    <string-array name="bubble_values">
        <item>0</item>
        <item>1</item>
        <item>2</item>
        <item>3</item>
        <item>4</item>
        <item>5</item>
        <item>6</item>
        <item>7</item>
        <item>8</item>
        <item>9</item>
        <item>10</item>
        <item>11</item>
    </string-array>
 
3. Copy bahan sesuai tempatnya.
4. Tambahkan <activity android:name="id.delta.bbm.activities.SettingsActivity"/> di AndroidManifest.xml
5. Buat tombol untuk pindah aktiviti, misalkan di drawer bisa menggunakan PORTAL dengan menambahkan fitur FlashLamp. Ganti kode Lcom/mod/flash/FlashLampActivity; dengan Lid/delta/bbm/activities/SettingsActivity; di smali activities/vc.smali (di bbm versi 3.0.0.18)
 
6. Buka layout chat_bubble_generic_incoming.xml ganti <FrameLayout menjadi <id.delta.bbm.ui.IncomingBubble di line 10 sehingga menjadi :
        <id.delta.bbm.ui.IncomingBubble android:layout_gravity="start" android:id="@id/content_specific_container" android:layout_width="wrap_content" android:layout_height="wrap_content" />
 
7. Buka layout chat_bubble_generic_outgoing.xml ganti <FrameLayout menjadi <id.delta.bbm.ui.OutgoingBubble di line 8 sehingga menjadi :
        <id.delta.bbm.ui.OutgoingBubble android:layout_gravity="end" android:id="@id/content_specific_container" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/conversation_chat_bubble_margin_outgoing" android:layout_marginRight="0.0dip" />
 
8. Jika sudah Recompile, Sign, Install.

Bahan Guide Ganti Bubble/Gelembung BBM

Read More

Friday, June 24, 2016

[SOURCE CODE] Mengubah Icon dan Label Aplikasi Menggunakan ListPreference

  No comments
5:41 AM

Assalamu'alaikum Teman, ini merupakan tutorial pertama dari saya, semoga bermanfaat buat teman-teman yang lagi suka dengan dunia pengkodean. Ini merupakan pengembangan dari sampel Application-Launcher-Icon-And-Name-Changer yang dibuat oleh Shabbir Dhangot.

1. Buat Project Baru dengan
 - Application name == IconLauncher
 - Company Domain == id.delta
 - Package name == id.delta.iconlauncher

 2. Buat class dengan nama SettingsActivity.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class SettingsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbars);
        setSupportActionBar(toolbar);

        getFragmentManager().beginTransaction().replace(R.id.content_frame, new SettingsFragment())
                .commit();
    }

    public static class SettingsFragment extends PreferenceFragment {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.settings);
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        Process.killProcess(Process.myPid());
    }
}

3. Buat layout baru dengan nama activity_settings.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?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:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context="id.delta.iconlauncher.SettingsActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbars"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:navigationIcon="?homeAsUpIndicator"
            app:navigationContentDescription="@string/abc_action_bar_up_description"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>


    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true" />


</LinearLayout>

4. Tambahkan kode berikut di AndroidManifest
1
<activity android:name=".SettingsActivity" android:theme="@style/AppTheme.NoActionBar" android:label="Settings"/>

5. Buka class MainActivity, di sini kita gunakan FloatingActionButton agar saat ditekan akan membuka SettingsActivity, cari kode berikut :
1
2
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();

Ganti dengan kode :
1
startActivity(new Intent(MainActivity.this, SettingsActivity.class));

6. Buka strings.xml dan tambahkan kode berikut :
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<string-array name="label_icons">
        <item>Red</item>
        <item>Green</item>
        <item>Blue</item>
    </string-array>
    <string-array name="value_icons">
        <item>0</item>
        <item>1</item>
        <item>2</item>
    </string-array>

7. Buat baru resource file dengan type xml dan nama settings.xml, tambahkan kode berikut di dalam PreferenceScreen
1
2
3
4
5
6
7
<ListPreference
        android:key="key_pref_icons"
        android:title="Icon Color"
        android:defaultValue="0"
        android:entries="@array/label_icons"
        android:entryValues="@array/value_icons"
        android:summary="%s"/>

8. Siapkan 3 Icon Anda dan rename menjadi
- ic_launcher_red
- ic_launcher_green
- ic_launcher_blue letakan di folder mipmap

9. Buat class baru dengan nama Utils.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
public class Utils {

    private Utils (){}

    public static void setIcon (Activity activity){
        Context context = activity;
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        int n = Integer.parseInt((String) preferences.getString("key_pref_icons", "0"));
        if (n == 0) {
            activity.getPackageManager().setComponentEnabledSetting(
                    new ComponentName("id.delta.iconlauncher", "id.delta.iconlauncher.MainActivity-Red"),
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
            try {
                activity.getPackageManager().setComponentEnabledSetting(
                        new ComponentName("id.delta.iconlauncher", "id.delta.iconlauncher.MainActivity-Green"),
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
                activity.getPackageManager().setComponentEnabledSetting(
                        new ComponentName("id.delta.iconlauncher", "id.delta.iconlauncher.MainActivity-Blue"),
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        if (n == 1){
            activity.getPackageManager().setComponentEnabledSetting(
                    new ComponentName("id.delta.iconlauncher","id.delta.iconlauncher.MainActivity-Green"),
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP);
            try {
                activity.getPackageManager().setComponentEnabledSetting(
                        new ComponentName("id.delta.iconlauncher","id.delta.iconlauncher.MainActivity-Red"),
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP
                );
                activity.getPackageManager().setComponentEnabledSetting(
                        new ComponentName("id.delta.iconlauncher","id.delta.iconlauncher.MainActivity-Blue"),
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP
                );
            }catch (Exception e){
                e.printStackTrace();
            }
        }

        if (n == 2){
            activity.getPackageManager().setComponentEnabledSetting(
                    new ComponentName("id.delta.iconlauncher", "id.delta.iconlauncher.MainActivity-Blue"),
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP
            );

            try {
                activity.getPackageManager().setComponentEnabledSetting(
                        new ComponentName("id.delta.iconlauncher","id.delta.iconlauncher.MainActivity-Red"),
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP
                );
                activity.getPackageManager().setComponentEnabledSetting(
                        new ComponentName("id.delta.iconlauncher","id.delta.iconlauncher.MainActivity-Green"),
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP
                );
            } catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}

10. Buka AndroidManifest di bagian activity MainActivity hapus kode
1
2
3
4
5
<intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

11. Bikin activity-alias di bawahnya :
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<activity-alias
            android:name=".MainActivity-Red"
            android:enabled="true"
            android:targetActivity=".MainActivity"
            android:icon="@mipmap/ic_launcher_red">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity-alias>

        <activity-alias
            android:name=".MainActivity-Green"
            android:enabled="false"
            android:targetActivity=".MainActivity"
            android:icon="@mipmap/ic_launcher_green">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity-alias>

        <activity-alias
            android:name=".MainActivity-Blue"
            android:enabled="false"
            android:targetActivity=".MainActivity"
            android:icon="@mipmap/ic_launcher_blue">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity-alias>

12. Buka class MainActivity.java tambahkan kode berikut di bawah super.onCreate(savedInstanceState);
1
Utils.setIcon(this);

13. Silahkan lakukan perintah Run
14. Semoga sukses
15. Jika belum jelas bisa download source kodenya di bawah


Read More