iOS my first App : 台鐵即時通

0 意見

https://itunes.apple.com/us/app/tai-tie-ji-shi-tong/id648330502?mt=8

Android LayoutParams ( change layout weight)

0 意見


TextView tv_value= (TextView)view.findViewById(R.id.value);
LayoutParams param= (LayoutParams) tv_value.getLayoutParams();
param.weight += 0.1;
tv_value.setLayoutParams(param);

Android set border and corner by style

0 意見


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
 <solid android:color="#FFFFFF"/>
 <stroke android:width="1.2dp" android:color="#AAAAAA" />
 
 <corners android:bottomRightRadius="5dp" android:bottomLeftRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp"/> 
</shape>

Java file path

0 意見


String filename = "test.png";                                                                               
String workingDir = System.getProperty("user.dir");                                                        
String pathFile = workingDir + File.separator + filename;


Android Loading Large Bitmaps Efficiently - BitmapFactory options

0 意見

http://developer.android.com/training/displaying-bitmaps/load-bitmap.html


Android place a listview into a scrollview

0 意見

reference from stack overflow


public class Utility {
    public static void setListViewHeightBasedOnChildren(ListView listView) {
        ListAdapter listAdapter = listView.getAdapter(); 
        if (listAdapter == null) {
            // pre-condition
            return;
        }

        int totalHeight = 0;
        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(params);
    }
}

Access Point Name

0 意見

http://en.wikipedia.org/wiki/Access_Point_Name

An Access Point Name (APN) is the name of a gateway between a GPRS (or 3G, etc) mobile network and another computer network, frequently the public Internet.
A mobile device making a data connection must be configured with an APN to present to the carrier. The carrier will then examine this identifier to determine what type of network connection should be created, for example: what IP addresses should be assigned to the wireless device, what security methods should be used, and how or if, it should be connected to some private customer network.

DMZ

0 意見

http://zh.wikipedia.org/wiki/DMZ

DMZ,正式名稱Demilitarized Zone,譯名為「非軍事區」,一種網路主機的布置方案,就是在不信任的外部網路和可信任的內部網路之間建立一個面向外部網路的物理或邏輯子網,該子網能安放用於對外部網路的伺服器主機。
該方案主要用於解決使用防火牆,處於內部網路的伺服器無法被外部網路訪問的問題。除外,由於從外部網路進入內部網路必須要經過隔離的DMZ與外部網路,和隔離內部網路與DMZ之間的隔離設備(如防火牆)和處於DMZ的主機(不一定經過),比一般的防火牆方案,從外部網路入侵內部網路的難度會有所增加,從而提供對內部網路的保護。對於外部網路來說,只能訪問到DMZ內的主機。

Android set password input type

0 意見

TextView tv = (TextView)view.findViewById(R.id.row_value);
tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

Android add progress in action bar tutorial

0 意見

This tutorial is form This blog, thanks.

private Menu optionsMenu;

// create options menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
 this.mOptionsMenu = menu;
 MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_action_bar_main, menu);
    return super.onCreateOptionsMenu(menu);
}

// change action button state (progress or refresh image)
public void setRefreshActionButtonState(final boolean refreshing)
{
    if (mOptionsMenu != null)
    {
        final MenuItem refreshItem = mOptionsMenu.findItem(R.id.airport_menuRefresh);
        if (refreshItem != null)
        {
            if (refreshing) {
                refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
            } else {
                refreshItem.setActionView(null);
            }
        }
    }
}


//activity_action_bar_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/airport_menuRefresh"
         android:title=""
         android:alphabeticShortcut="r"
         android:orderInCategory="1"
         android:showAsAction="always" />
</menu>

// actionbar_indeterminate_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_height="wrap_content"
   android:layout_width="56dp"
   android:minWidth="56dp">
    <ProgressBar android:layout_width="32dp"
       android:layout_height="32dp"
       android:layout_gravity="center"/>
</FrameLayout>

Android detect keydown event in activity

0 意見


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
 if(keyCode == KeyEvent.KEYCODE_BACK)
 {
  //blah blah 
 }
 return true;
}

Android set text style bold

0 意見


android:textStyle="bold"


Android set cursor postion at the end of the text field

0 意見


EditText et = (EditText)findViewById(R.id.value);
et.setSelection(et.getText().length());


Android embedded a spinner to alert and set adapter by array list( or string array)

0 意見

AlertDialog.Builder alert = new AlertDialog.Builder(SiteAddEdit.this);
alert.setTitle("As Title");
alert.setMessage("This is message");

ArrayList options = new ArrayList();
for(int j=0 ; j<10 ; j++)
 options.add(j+"");

LayoutInflater li = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = li.inflate(R.layout.spinner_window, null);
Spinner sp = (Spinner)view.findViewById(R.id.spinner_refresh);
ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_item, options);

// or by string array
ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.enabled_array, android.R.layout.simple_spinner_item);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp.setAdapter(adapter);

sp.setSelection(0);

alert.setView(view);
alert.show();


string.xml
<string-array name="enabled_array">
    <item>DISABLED</item>
    <item>ENABLED</item>
</string-array>

Android set Marker with custom marker

0 意見

Markers|Developer
reference to bon-app-etit

private void setMarker(final LatLng gps, final String title, final String desc, int resource)
{
 MarkerOptions markerOpt = new MarkerOptions()
 .position(gps)
 .title(title)
 .snippet(desc)
 .icon(BitmapDescriptorFactory.fromResource(resource));
 
 mGoogleMap.addMarker(markerOpt);
  
 InfoWindowAdapter iwa = new InfoWindowAdapter() {
         private final View contents = getActivity().getLayoutInflater().inflate(R.layout.custom_marker, null);
  
  @Override
  public View getInfoWindow(Marker arg0) {
   // TODO Auto-generated method stub
   return null;
  }
  
  @Override
  public View getInfoContents(Marker marker) {
      String title = marker.getTitle();
      TextView txtTitle = ((TextView) contents.findViewById(R.id.txtInfoWindowDesc));

             if (title != null) {
                 SpannableString titleText = new SpannableString(title);
                 txtTitle.setText(titleText);
             } else {
                  txtTitle.setText("");
         }
              
         TextView txtType = ((TextView) contents.findViewById(R.id.txtInfoWindowGps));
         txtType.setText(marker.getSnippet());
              
          return contents;

  }
 };
  
 mGoogleMap.setInfoWindowAdapter(iwa);
}


xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  android:paddingRight="10dp">
  
  <ImageView
    android:id="@+id/ivInfoWindowMain"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_margin="10dp"
    android:adjustViewBounds="true"
    android:src="@drawable/tab_overview2">
  </ImageView>

  <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="vertical">
    
    <TextView
      android:id="@+id/txtInfoWindowDesc"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="left"
      android:ellipsize="end"
      android:singleLine="true"
      android:textColor="#ff000000"
      android:textSize="14dp"
      android:textStyle="bold"/>

    <TextView
      android:id="@+id/txtInfoWindowGps"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:ellipsize="end"
      android:singleLine="true"
      android:textColor="#ff7f7f7f"
      android:textSize="14dp"/>
  </LinearLayout>
</LinearLayout>

Android set map to center

0 意見

GoogleMap mGoogleMap;
LatLng mCurrentLatLng = new LatLng(loc.getLatitude(), loc.getLongitude());
mGoogleMap.moveCamera( CameraUpdateFactory.newLatLngZoom(mCurrentLatLng , 8.0f) );

Android CreateContextMenu

0 意見


onCreateView ==> registerForContextMenu(mListView);

public void onCreateContextMenu(ContextMenu menu, View v,ContextMenu.ContextMenuInfo menuInfo)
{
    MenuInflater inflater = getActivity().getMenuInflater();
    menu.setHeaderTitle("Rmove a selected site");     
    inflater.inflate(R.menu.menu_main_context, menu);
}


xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@+id/cancel" android:title="OK"/>
  <item android:id="@+id/cancel" android:title="Cancel"/>
</menul>

Android doing timer function by handler postDelayed and Running

0 意見


private Handler mHandler = new Handler();

private final Runnable timerGo = new Runnable()
{
    public void run()
    {
 //blahblah
    }
};

mHandler.postDelayed(timerGo, 3000);

iOS get seconds by string

0 意見


NSString *datestr = @"2013/05/02 08:06";

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy/MM/dd H:mm"];
    
NSDate *ticket_date = [df dateFromString:datestr];
NSTimeInterval seconds = [ticket_date timeIntervalSinceNow];
    
NSLog(@"%@  seconds : %f", datestr, seconds);