Android Gauge Library

root build.gradle

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.github.Paroca72:sc-widgets:2.1.2'
    testCompile 'junit:junit:4.12'

}

References
https://github.com/mhdr/AndroidSamples/tree/master/080

Store the result of query into a variable in MySQL

INSERT INTO users (first_name, last_name, password, user_name)
VALUES (N'ادمین',
        N'ادمین',
        N'c7ad44cbad762a5da0a452f9e854fdc1e0e7a52a38015f23f3eab1d80b931dd472634dfac71cd34ebc35d16ab7fb8a90c81f975113d6c7538dc69dd8de9077ec',
        N'admin');

INSERT INTO permissions (id, name) VALUES (1, N'ادمین');

SET @insertedId := (SELECT id
                    FROM users
                    WHERE user_name = N'admin');

INSERT INTO user_permissions (permission_id, user_id)
VALUES (1, @insertedId);

Android Gradient Background Color for Button

/res/drawable/gradient_color.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >

    <gradient
        android:angle="135"
        android:startColor="@color/colorBackground"
        android:endColor="@color/colorPrimary"
        android:type="linear" />

    <corners
        android:radius="0dp"/>

</shape>

activity_main.xml

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/editTextWeight"
                android:background="@drawable/gradient_color">
                <Button
                    android:id="@+id/buttonStart"
                    android:background="?android:attr/selectableItemBackground"
                    android:textAllCaps="true"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/start"
                    />
            </FrameLayout>

References
https://github.com/mhdr/AndroidSamples/tree/master/077

Android Focus on TextView

activity_main.xml

            <TextView
                android:id="@+id/textViewProfileName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_below="@+id/textViewFirstRunHeader2"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="center|start"
                android:text="@string/profile_name"
                android:textColor="@android:color/black"
                android:textSize="16sp"
                android:textStyle="bold" />

MainActivity.java

        textViewProfileName= (TextView) findViewById(R.id.textViewProfileName);
        textViewProfileName.requestFocusFromTouch();

References
https://github.com/mhdr/AndroidSamples/tree/master/075

Android Custom Farsi Font for Views Using Calligraphy Library

build.gradle

dependencies {
    compile 'uk.co.chrisjenx:calligraphy:2.2.0'
}

Add Application Class :
MyApplication.java

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                .setDefaultFontPath("fonts/BYekan.ttf")
                .setFontAttrId(R.attr.fontPath)
                .build());
    }
}

Register your Application Class :
AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ir.mhdr.a072">

    <application
        android:allowBackup="true"
        android:name=".MyApplication"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

Add attachBaseContext to all Activities

MainActivity.java

public class MainActivity extends AppCompatActivity {

    NumberPicker numberPicker;

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

        numberPicker= (NumberPicker) findViewById(R.id.numberPicker);
        numberPicker.setMinValue(0);
        numberPicker.setMaxValue(99);
        numberPicker.setValue(24);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(CalligraphyContextWrapper.wrap(base));
    }
}

References
https://github.com/mhdr/AndroidSamples/tree/master/073
https://github.com/chrisjenx/Calligraphy
https://blog.goyello.com/2014/08/01/how-to-use-custom-fonts-in-android-apps-and-not-get-fat-3/

Android Custom Farsi Font for Views Using TypeFace

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="ir.mhdr.a071.MainActivity">

    <TextView
        android:id="@+id/textViewMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World 12!"
        android:layout_below="@+id/numberPicker"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="115dp" />

    <ir.mhdr.a071.CustomNumberPicker
        android:id="@+id/numberPicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:gravity="center" />

</RelativeLayout>

CustomNumberPicker.java

public class CustomNumberPicker extends NumberPicker {

    public CustomNumberPicker(Context context) {
        super(context);
    }

    public CustomNumberPicker(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomNumberPicker(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void addView(View child) {
        super.addView(child);

        updateView(child);
    }

    @Override
    public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) {
        super.addView(child, index, params);
        updateView(child);
    }

    @Override
    public void addView(View child, android.view.ViewGroup.LayoutParams params) {
        super.addView(child, params);
        updateView(child);
    }

    private void updateView(View view) {

        Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/BNazanin.ttf");

        if(view instanceof EditText) {
            ((EditText) view).setTypeface(typeface);
        }

        if (view instanceof TextView)
        {
            ((TextView) view).setTypeface(typeface);
        }
    }
}

MainActivity.java

public class MainActivity extends AppCompatActivity {

    TextView textViewMessage;
    CustomNumberPicker numberPicker;

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

        textViewMessage = (TextView) findViewById(R.id.textViewMessage);

        // the base way to do this in android
        // the font is placed on assets/fonts/BNazanin.ttf
        Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/BNazanin.ttf");
        textViewMessage.setTypeface(typeface);


        // for other views we need to extend view
        numberPicker = (CustomNumberPicker) findViewById(R.id.numberPicker);
        numberPicker.setMinValue(0);
        numberPicker.setMaxValue(99);
        numberPicker.setValue(34);
    }
}

References
https://github.com/mhdr/AndroidSamples/tree/master/071