Thursday, May 17, 2018

android What is the difference between GridView for dynamicallty add item vs GridLayout for statically view

<GridLayout    android:layout_width="match_parent"    android:layout_height="0dp"    android:layout_weight="2"    android:alignmentMode="alignBounds"    android:rowCount="2"    android:columnCount="2"    android:columnOrderPreserved="false"    android:padding="@dimen/gap16"    android:orientation="horizontal">

    <android.support.v7.widget.CardView        android:layout_columnWeight="1"        android:layout_rowWeight="1"        android:layout_gravity="fill"        android:layout_column="0"        android:layout_row="0"        android:layout_margin="@dimen/gap16"        app:cardCornerRadius="@dimen/gap3"        app:cardElevation="@dimen/gap3">

        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_gravity="fill"            android:orientation="vertical">

            <Button                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:text="button 1"                android:background="@color/colorOdoOrange"                android:textColor="@color/colorWhite" />
        </LinearLayout>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView        android:layout_columnWeight="1"        android:layout_rowWeight="1"        android:layout_gravity="fill"        android:layout_column="1"        android:layout_row="1"        android:layout_margin="@dimen/gap16"        app:cardCornerRadius="@dimen/gap3"        app:cardElevation="@dimen/gap16">

        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_gravity="fill"            android:orientation="vertical">

            <Button                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:text="button 2"                android:background="@color/colorOdoOrange"                android:textColor="@color/colorWhite" />
        </LinearLayout>
    </android.support.v7.widget.CardView>

</GridLayout>


VS


<mn.odo.ordersystem.components.OdoGridView    android:id="@+id/lv_goods_images"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:layout_marginTop="@dimen/gap16"    android:layout_marginBottom="@dimen/gap16"    android:isScrollContainer="false"    android:columnWidth="0dp"    android:gravity="center"    android:numColumns="5"    android:stretchMode="columnWidth"    android:horizontalSpacing="@dimen/gap0"    android:verticalSpacing="@dimen/gap0" />


gridview item:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:orientation="vertical">

    <Button        android:id="@+id/item_image"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:background="@color/colorBgSubTitleBlue"        android:text="button 0" />

</LinearLayout>

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()