Showing posts with label begginers. Show all posts
Showing posts with label begginers. Show all posts

06 November 2016

Android Dynamically Change Style colors

In this Tutorial I will discuss How to Change Android Style theme colors. Last few days I had to I have searched how to change android theme style color dynamically but android doesn't support to change theme colors dynamically. (Note :You can changed android pre-defined theme styles dynamically not the dynamic generated themes)

If we using Theme.AppCompat.Light.DarkActionBar then these are the main properties in layout.



If You want to change theme what you did was change the primary color and primaryDark color. And this code helps you to dynamically change the theme (above mention colors) colors.

This is for change primary Dark color.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
public static void setStatusBarColor(String color) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = currentActivity.getWindow();
        int statusBarColor = Color.parseColor(color);

        if (statusBarColor == Color.BLACK && window.getNavigationBarColor() == Color.BLACK) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        } else {
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        }
        window.setStatusBarColor(statusBarColor);
    }
}




This is for change primary color


1
2
getSupportActionBar().setBackgroundDrawable(
        new ColorDrawable(Color.parseColor("#AA3939")));



I hope this article help you to resolve your problem.
Thanks

24 January 2015

Linux Interactive Shell Scripting

Last week i saw interactive shell running in the juju-quickstart . It is really cool.So i search about interactive shell scripting techniques available in Linux.So i found one of the famous method is "Whiptail" . Basically these scripting used for displaying dialog boxes which used to get user Inputs.So I have created Sample Interactive shell Scripting using dialog boxes.


First Screen Start with Menus.


This is the confirm box with yes / no option.
 This is the Password box. In this script i have put another Input box.

This is the Progress bar in "whiptail".Here i will put the bash script file.


 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# Whiptail is the interactive shell Scrpting
OPTION=$(whiptail --title "Whiptail Shell Script Menu" --menu "Choose your option" 15 60 4 \
"1" "Change Password" \
"2" "Change UserName" \
"3" "Change Email" \
"4" "exit"  3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "Your chosen option:" $OPTION

case $OPTION in
  1) echo "Option1 Selected"
     if (whiptail --title "Change Password" --yes-button "Yes" --no-button "No"  --yesno "Do you need to changed Password ?" 10 60) then
    echo "password Selection Yes$?."
     
    # Start Password Box
    PASSWORD=$(whiptail --passwordbox "please enter your secret password" 8 78 --title "Change Password" 3>&1 1>&2 2>&3)
                                                                        # A trick to swap stdout and stderr.
    # Again, you can pack this inside if, but it seems really long for some 80-col terminal users.
     exitstatus=$?
 if [ $exitstatus = 0 ]; then
     echo "User selected Ok and entered " $PASSWORD
     touch sample_out_put.txt
     echo $PASSWORD > sample_out_put.txt
            
            # Start Progress Bar
      {
       for ((i = 0 ; i <= 100 ; i+=5)); do
  sleep 0.3
  echo $i
     done
      } | whiptail --gauge "Password Updating.." 6 50 0
            # End Progress Bar    

 else
     echo "User selected Cancel."
 fi

    # End Password Box 
     else
    echo "Password Selection No$?."
     fi
     ;;
  2) echo "option2 Selected"
 # Change User Name Box
 NAME=$(whiptail --inputbox "Change Username " 8 78  --title "Changed UserName" 3>&1 1>&2 2>&3) 
 exitstatus=$?
 if [ $exitstatus = 0 ]; then
     echo "UserName Changed " $NAME
 if (whiptail --title "Confirm Change UserName" --yes-button "Yes" --no-button "No"  --yesno "Do you need to changed UserName ?" 10 60)  then
     echo "Username Confirm Yes$?."
     # Start Progress Bar
      {
       for ((i = 0 ; i <= 100 ; i+=5)); do
  sleep 0.3
  echo $i
       done
      } | whiptail --gauge "UserName Updating.." 6 50 0
            # End Progress Bar 
 else
  echo"Confirm Failed"
 fi

 else 
    echo "UserName Not Changed"
 fi

     ;;
  3) echo "Option3 Selected"
     
     ;;
  4) echo "exit"
     {
    for ((i = 0 ; i <= 100 ; i+=5)); do
        sleep 0.1
        echo $i
    done
     } | whiptail --gauge "exit..." 6 50 0
esac

else
    echo "You chose Cancel."
fi

And Happy Coding....