Sunday, May 13, 2018

android kotlin tablayout child tab ViewGroup.MarginLayoutParams setMargins, setPadding with padding dp to px

val slidingTabStrip = tabs.getChildAt(0) as ViewGroup
for (i in 0 until slidingTabStrip.childCount - 1) {
    val v = slidingTabStrip.getChildAt(i)
    val p = v.getLayoutParams() as ViewGroup.MarginLayoutParams
    p.setMargins(0, 0, 0, 0)

    val scale = resources.displayMetrics.density
    var pxl = resources.getDimensionPixelSize(R.dimen.gap1)
    val padding_in_dp = 3    val padding_in_px = (padding_in_dp * scale + 0.5f).toInt()
    v.setPadding(pxl, pxl, pxl, pxl)
}

Saturday, May 12, 2018

android activity theme customize colors

<activity    android:name=".LoginActivity"    
android:label="@string/app_name"    
android:screenOrientation="portrait"    
android:theme="@style/LoginTheme.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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


<!-- Login application theme. --><style name="LoginTheme" 
parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="LoginTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>


  • colorPrimary – The color of the app bar.
  • colorPrimaryDark – The color of the status bar and contextual app bars; this is normally a dark version of colorPrimary.
  • colorAccent – The color of UI controls such as check boxes, radio buttons, and edit text boxes.
  • windowBackground – The color of the screen background.
  • textColorPrimary – The color of UI text in the app bar.
  • statusBarColor – The color of the status bar.
  • navigationBarColor – The color of the navigation bar.
you can use following link to setup your style.

Tuesday, May 1, 2018

python Flask, make_response, redirect, session, url_for

from flask import Flask, make_response, redirect, session, url_for

SECRET_KEY = 'develop'

app = Flask(__name__)
app.config.from_object(__name__)

@app.route('/')
def index():
    return '<a href="%s">Go here.</a>' % url_for('do_redirect')

@app.route('/redirect/')
def do_redirect():
    session['hello'] = 'world!'
    return redirect(url_for('dump_session'))

@app.route('/session/')
def dump_session():
    response = make_response(repr(session))
    response.content_type = 'text/plain'
    return response

if __name__ == '__main__':
    app.run()

Monday, April 30, 2018

android check whether internet is available or not.

//check whether internet is available or not.
    public boolean isReachable(String address, int port, int timeoutMs) {
        try {
            Socket sock = new Socket();
            SocketAddress sockaddr = new InetSocketAddress(address, port);

            sock.connect(sockaddr, timeoutMs); // this will block no more than timeoutMs
            sock.close();

            return true;

        } catch (IOException e) { return false; }
    }