Android: Check if Airplane mode is on

January 8, 2011 Leave a comment

This will help u check if your android is in airplane/fight mode

static boolean isAirplaneEnabled;
isAirplaneEnabled = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1;

Enjoy.. 😉 !!!!!!!

Categories: Android Tags: ,

Customize button in Android

November 9, 2010 32 comments


hi!!
You can change the appearance of button in android like make the corners of button rounded etc…

button_shape.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape      xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
    
    <solid   android:color="#EAEAEA"/>
    
    <corners    android:bottomLeftRadius="8dip"
                android:topRightRadius="8dip"
                android:topLeftRadius="1dip"
                android:bottomRightRadius="1dip"
                />
</shape>

here you can change the radius of corners

you can use this button_shape in your button’s code as

android:background=”@drawable/button_shape”

here’s the code

main.xml

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

    <TextView   android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Hello Android from NetBeans"/>

    <Button android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nishant Nair"
            android:padding="5dip"
            android:layout_gravity="center"
            android:background="@drawable/button_shape"
            />

</LinearLayout>

you can add an image to your button by using drawable

android:drawableTop=”@drawable/pdf”

in your button’s xml code

this will look like this

Enjoy.. 😉 !!!!!!!

Categories: Android Tags: ,

Get details of item(component,schema etc…) through Buisness Connector in SDL Tridion

October 7, 2010 3 comments

This code helps us to retrieve all the details of a particular item.
I have used Business Connector to connect with sdl tridion.
This code is written in console application(c# .net)

public void Details()
{
      public StringBuilder stringbuilder = new StringBuilder();

      #region ..item details..
     
      string path;
      /*this is used to get template from external source,
      for which we have created a folder in our project named as temp
      in that we have a stringTemplate named as folder.st */
      path = Environment.CurrentDirectory + "\\temp";

      StringTemplateGroup grp = new StringTemplateGroup("myGroup", path);
      StringTemplate query = grp.GetInstanceOf("folder");

      /* this is to fetch details of the item for which id is specified */
      query.SetAttribute("itemuri", "tcm:88-11828");
            
      /* this connects to tridion */
      BusinessConnector service = new BusinessConnector();
      service.Credentials = new System.Net.NetworkCredential("administrator", "admin");

            
      string BC = service.execute("default", query.ToString(), null);
      Console.WriteLine(BC);

      /*stringbuilder is used to print out put on external file*/
      stringbuilder.AppendFormat(@"{0}",BC);
      stringbuilder.Append(Environment.NewLine);

      /*name of the file to which we have to store*/
      File.WriteAllText(@"c:\ShowComponentRaw.xml", stringbuilder.ToString());

            
      #endregion ..item details...
}

Here’s the template
/*save it as .st because its string template */
folder.st

<?xml version='1.0'?>
<tcmapi:Message xmlns:tcmapi="http://www.tridion.com/ContentManager/5.0/TCMAPI"
version="5.0" from="Nishant" failOnError="false">
<tcmapi:Request ID="Request1" preserve="false">
  <tcmapi:GetItem itemURI="$itemuri$" writeBinaryToDisk="true">
    <tcmapi:ItemFilter type="XMLReadAll"/>
  </tcmapi:GetItem>
</tcmapi:Request>
</tcmapi:Message>

Enjoy.. 😉 ..!!!

Categories: SDL Tridion Tags: , ,

Remove HTML tags using regular expressions

October 6, 2010 Leave a comment

Hi.

<\/?\w[^>]*>
      or
<(.|\n)*?>
      or
<[^>]+>
      or
<\\??.+?>
      or
<[^]+>

This will help u to remove all html tags.

Enjoy.. 😉 ..!!!

Categories: .NET, Regex Tags: ,

Extract content within tags : Regular Expression

October 6, 2010 Leave a comment

By this you can extract content which is in span tag or any tag

<span[^> ]*>(.*?)</span>

here you can use any tag like h1 or p etc…

Enjoy.. 😉 ..!!!

Categories: .NET, Regex Tags: ,

Change color of button on click :Android

October 5, 2010 7 comments

This is used to change color of button on pressed or focused
write this code in your drawable folder

login_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Button Focused-->
    <item   android:state_focused="true"
            android:state_pressed="false"
            android:drawable="@drawable/login_hover"
            />
<!-- Button Focused Pressed-->
    <item   android:state_focused="true"
            android:state_pressed="true"
            android:drawable="@drawable/login_hover"
            />
<!-- Button Pressed-->
    <item   android:state_focused="false"
            android:state_pressed="true"
            android:drawable="@drawable/login_hover"
            />
<!-- Button Default Image-->
    <item   android:drawable="@drawable/login_bg"/>

</selector>

login_hover.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" shape="rectangle">
<!--this is to give gradient effect -->
<gradient   android:angle="270"
               android:startColor="#6b6b6b"
               android:endColor="#0e0e0e"
               />
<!-- this is make corners of button rounded -->
<corners    android:topLeftRadius="5dip"
               android:bottomRightRadius="5dip"
               android:topRightRadius="5dip"
               android:bottomLeftRadius="5dip"/>

</shape>

login_bg.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" shape="rectangle">
<!--this is to give gradient effect -->
<gradient   android:angle="270"
            android:startColor="#e7ff47"
            android:endColor="#90a501"
            />
<!-- this is make corners of button rounded -->
<corners    android:topLeftRadius="5dip"
               android:bottomRightRadius="5dip"
               android:topRightRadius="5dip"
               android:bottomLeftRadius="5dip"/>

</shape>

and in your code in res/layout/login.xml
or in your button’s code
android:background=”@drawable/login_selector”

Enjoy.. 😉 ..!!!

Categories: Android Tags: ,

Fading color effect with TransitionDrawable :Android

October 5, 2010 3 comments
RelativeLayout layout = (RelativeLayout) findViewById(R.id.Layout);
layout.setBackgroundResource(R.drawable.translate);
TransitionDrawable transition = (TransitionDrawable) layout.getBackground();
transition.startTransition(5000);

This code gives you a fading effect like from yellow to white(original color).

translate.xml

<?xml version="1.0" encoding="UTF-8"?>
   <transition xmlns:android="http://schemas.android.com/apk/res/android">
          <!-- The drawables used here can be solid colors, gradients, shapes, images, etc. -->
          <item android:drawable="@drawable/new_state" />
          <item android:drawable="@drawable/original_state" />
   </transition>

new_state.xml

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

original_state.xml

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

Enjoy.. 😉 ..!!!

Categories: Android Tags: , ,
%d bloggers like this: