Mar 20, 2014

How to JAR converter to EXE using jsmooth.



You move to this site. 
You can see this page.

Down to 'jsmooth-0.9.9-7-setup.exe' 

If download is completed , you will install program.

​Go to eclipse.

Select 'File' and 'Export'


You select 'Java'->'Runnable JAR file' and click to 'Next '.



You will select this...

Launch configuration : select your java project

Export destination : export folder and file name

and click to 'Finish'



If eclipse showed to notiifation windows, you click to 'OK'

Then, run to 'jSmooth'

You click to 'Skelecton' tab.

If your java program is GUI program, select 'Windowed Wrapper'


Then, Click to 'Executable' tab.



And insert this.

Executable Binary : file name(***.exe)

Executable Icon : file's icon


Then go to next tab,Application.

Main class : your file's main class

Embedded jar settings check to 'Use an embedded jar'and insert your jar file.

Then, go to JVM Sel... tab. 


Typing Minimum and Maximum JVM version.

If you type to large range, file size is bigger than small range.

And last step, you click to 'gear mark' icon

and you can see save window.


This window is saving for jsmooth configration. 

Typing file name and click to save.


Complete!!


You can see icon.

first is JAR file, second is EXE file and cofiguration file.

click to exe file


If you want to release, just need EXE file.





Mar 19, 2014

Tcp/Ip Client program Using JAVA Swing




This program is Tcp/Ip communication program.

This is Client.

You fist run to this application.

You can see below image.


You typed sever ip and port then click to Connect button.

If successfully connected , you can see changed button's text.


Then, typing text and click to send button.

Your typed text send to server and program's text window.


If you want HEX .

Changing spinner and click to '변환'button.

You can see change text.


This image is communication to server with client.


My code include annotation.

Mar 13, 2014

Notification



Notification is useful class in android.

You can see easily notification in your phone when if you received SMS or email, etc...

This is my code.

  1. NotificationManager nm=(NotificationManager)mContext.getSystemService(mContext.NOTIFICATION_SERVICE);
  2. int icon=setIcon(weathericon);
  3. Notification notification =new Notification(icon,"날씨가 업데이트 되었습니다",System.currentTimeMillis());
  4. PendingIntent pi=PendingIntent.getActivity(mContext, 0new Intent(mContext,MainActivity.class),0);
  5. if(dbnotify.equals("notifyUse")){
  6.     notification.flags=Notification.FLAG_AUTO_CANCEL;
  7. }else if(dbnotify.equals("notifyOngoing")){
  8.     notification.flags=Notification.FLAG_ONGOING_EVENT;
  9. }
  10. notification.setLatestEventInfo(mContext, name, weather, pi);
  11. nm.notify(notifyId,notification);

I not use vibration& sound. If you will use vibration& sound that add this code

  1. notification.flags=Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE;


 You can see to above notification bar "날씨가 업데이트 되었습니다." 

  1. Notification notification =new Notification(icon,"날씨가 업데이트 되었습니다",System.currentTimeMillis());
The code making that notification bar.

Notification was deprecated but possibly to use. 

If you down scroll notification bar that can see this picture.

  1. PendingIntent pi=PendingIntent.getActivity(mContext, 0new Intent(mContext,MainActivity.class),0);
  2. notification.setLatestEventInfo(mContext, name, weather, pi);
Pending intent is set will moving activity when you touched notification.

setLatesetEventinfo is notification data.

  1. notification.flags=Notification.FLAG_AUTO_CANCEL;
This flag is notification property.

If you want ongoing mode that need this code

notification.flags=Notification.FLAG_ONGOING_EVENT;







Mar 11, 2014

78M6613 spec



FEATURES

• < 0.5% Wh Accuracy Over Wide 2000:1 Current Range and Over Temperature

• Voltage Reference < 40ppm/°C

• Four Sensor Inputs—V3P3A Referenced

• 22-Bit Delta-Sigma ADC with Independent 32-Bit Compute Engine (CE)

• 8-Bit MPU (80515), One Clock Cycle per Instruction with 2KB MPU XRAM

• 32KB Flash with Security

• Integrated In-Circuit Emulator (ICE) Interface for MPU Debug

• 32kHz Time Base with Hardware Watchdog Timer

• UART Interface and Up to 10 General- Purpose 5V Tolerant I/O Pins

• Packaged in a RoHS-Compliant (6/6) Lead(Pb)-Free, 32-Pin QFN (5mm x 5mm)

• Complete Application Firmware Provides:

o True RMS Calculations for Current, Voltage, Line Frequency, Real Power, Reactive Power, Apparent Power, and Power Factor

o Accumulated Watt-Hours, Kilowatt-Hours

o Intelligent Switch Control at Zero Crossings

o Digital Temperature Compensation

o Phase Compensation (±15°)

o Quick Calibration Routines

o 46–64Hz Line Frequency Range with Same Calibration

Mar 7, 2014

SimpleDateFormat




If you want show date,time in your program, can use this class.

'SimpleDateFormat' is useful class.

This class is java class.

But we use in android.

We can referenced Oracle document.

This figure is variable for SimpleDateFormat.


I introduce some examples.
If current date&time is 2014-03-07 12:00pm.

  1. Date date=new Date(System.currentTimeMillis());
  2. SimpleDateFormat CurTimeFormat=new SimpleDateFormat("hh:mm");
  3. String time=CurTimeFormat.format(date);
time==>12:00
If you want add 'am or pm'.

  1. Date date=new Date(System.currentTimeMillis());
  2. SimpleDateFormat CurtimeFormat=new SimpleDateFormat("a hh:mm");
  3. String time=CurtimeFormat.format(date);
time==> pm 12:00

If you want show current date
  1. Date date=new Date(System.currentTimeMillis());
  2. SimpleDateFormat CurDateFormat=new SimpleDateFormat("yyyy-MM-dd");
  3. String currentdate=CurDateFormat.format(date);
currentdate==> 2014-03-07

If you want add day in week, just add 'E'
  1. Date date=new Date(System.currentTimeMillis());
  2. SimpleDateFormat CurDateFormat=new SimpleDateFormat("YYYY-MM-dd E");
  3. String currentdate=CurDateFormat.format(date);
currentdate==> 2014-03-07 Fri

Mar 5, 2014

Digital clock Appwidget using Alarm manager




First you make Appwidget , if you need reference, can reference or my example.

Then you will layout digital clock on your widget.

Fortunately, you can see 'Digital Clock' widget view.

If you use 'Digital Clock'widget on your widget, can seen be below error image.




Because widget not support 'Digital Clock'. Just support 'Analog Clock'.

You can see reference, support widget classes.


A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:
And the following widget classes:
So, you will make a Digital Clock using text view and alarm manager.

Step 1. make a text view.


widget.xml
  1.  <TextView
  2.                     android:id="@+id/widgetclock"
  3.                     android:layout_width="184dp"
  4.                     android:layout_height="71dp"
  5.                     android:gravity="center"
  6.                     android:textColor="#ffffffff"
  7.                     android:text="12:12"
  8.                     android:textSize="60dp"
  9.                     android:textStyle="bold" />
You will typing 'id'.

This is important.

Step 2. register alarm manager.

widget.java

  1. @Override
  2.     public void onUpdate(Context context, AppWidgetManager appWidgetManager,
  3.             int[] appWidgetIds) {
  4.        
  5.         super.onUpdate(context, appWidgetManager, appWidgetIds);
  6.         setTime(context);
  7.         ...
You will typing function for initialize  in 'onUpdate' method.

  1.     public void setTime(Context context){
  2.         PendingIntent service = null;
  3.         final AlarmManager m = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
  4.         final Intent si = new Intent(context, alarmService.class);
  5.         if (service == null)
  6.         {
  7.             service = PendingIntent.getService(context, 0, si, PendingIntent.FLAG_CANCEL_CURRENT);
  8.         }
  9.         Log.d("timeService""start");
  10.         m.setRepeating(AlarmManager.RTCSystem.currentTimeMillis(),1000,service);
  11.     }
This function is register alarm manager and start service.

Important is 'setRepeating'. This method is repeated send service every 1sec in my case.

1000 is millisecond unit.

Step 3. make a service.java

service.java

  1.     @Override
  2.     public int onStartCommand(Intent intent, int flags, int startId)
  3.     {
  4.         update();
  5.         return super.onStartCommand(intent, flags, startId);
  6.     }
If service start when 'onStartCommand' start.

So, need a your function in 'onStartCommand' method.

  1.     private void update()
  2.     {
  3.             String time = getTime();
  4.         AppWidgetManager manager = AppWidgetManager.getInstance(this);
  5.         ComponentName weatherwidget = new ComponentName(this, WeatherWidget.class);
  6.         int[]ids = manager.getAppWidgetIds(weatherwidget);
  7.         final int N = ids.length;
  8.         for (int i = 0; i < N; i++){
  9.             int awID = ids[i];
  10.             RemoteViews views = new RemoteViews(getPackageName(), R.layout.widgetlayoutx2);
  11.             views.setTextViewText(R.id.widgetclock,time)         
  12.             manager.updateAppWidget(awID, views);
  13.         }
  14.     }
This function is update your digital clock on appwidget.

First highlight is getting clock infomation.

Second highlight is setting clock in your widget.

  1.     public String getTime(){
  2.        
  3.         String time=null;
  4.         Date date=new Date(System.currentTimeMillis());
  5.         SimpleDateFormat CurTimeFormat=new SimpleDateFormat("HH:mm");
  6.         time=CurTimeFormat.format(date);
  7.         return time;
  8.     }
This is getting current time using java api.

Step last. register AndroidManifest.xml

  1. <service android:enabled="true" android:name=".alarmService" />
If you don't register Manifest, service doesn't work.


Also, you will use alarm manager for widget update.

Because, android widget update time is minimum 30 min.


Mar 3, 2014

How to insert adMob in my android app?



Step 1

You need a adMob account.

You are going to adMob page and create an account.



If already have an account, need a log in.

You can be seen to below image, if you log in first time.

This is important!!!

'Country' is choose your country.

'Account Type' choose your type.

'Business Name' typing your company name or your name.

And choose received pay type. ACH/Wire or PayPal.

If you choose ACH/Wire, you receive when earn over $100 but you choose PayPal, you receive when earn over $20.

If you Korean, you can reference 'Bank SWIFT Code'  to this site.  




Step 2

You log in adMob and click to' Add Site/App' in 'Sites&Apps' tab.


And choose Android App ,you can be seen to below image.



Need a fill.

'App name' is your app name.

'Android package URL' is your app market's URL. If you don't have a market URL , just typing http://

'Category' is app's category.

'App descriptions' is your app description.

'Other Google Ads' is choose ad method. maybe first is good method.

And  click to 'Continue' after fill a secret number.


Step 3

You download SDK.

Unzip SDK and Open your eclipse project.

Copy 'GoogleAdMobAdsSdk-6.4.1.JAR' in zip file to android project libs folder.



And Coding your project.

JAVA file

  1. import com.google.ads.AdRequest;
  2. import com.google.ads.AdView;
  3. ....
  4. public class MainActivity extends Activity  implements OnClickListener,OnItemSelectedListener  {
  5.    
  6.     AdView adView;
  7.    
  8.     .............
  9.    
  10.     @Override
  11.     public void onCreate(Bundle savedInstanceState) {
  12.         super.onCreate(savedInstanceState);
  13.         setContentView(R.layout.activity_main);
  14.    
  15.        
  16.         AdView adView = (AdView)this.findViewById(R.id.adView);
  17.         adView.loadAd(new AdRequest());
  18.         .............
  19.     }
  20. ................
  21. }
XML file

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
  3.    android:layout_width="match_parent"
  4.    android:layout_height="match_parent"
  5.    android:orientation="vertical"
  6.    xmlns:tools="http://schemas.android.com/tools"
  7.    tools:context=".MainActivity" >
  8.    
  9.     <com.google.ads.AdView
  10.        android:id="@+id/adView"
  11.        android:layout_width="wrap_content"
  12.        android:layout_height="wrap_content"
  13.        ads:adUnitId="your KEY"
  14.        ads:adSize="SMART_BANNER"
  15.        ads:loadAdOnCreate="true"/>
You getting 'adUnitId' in adMob page.(sites& apps tab->your app name click)



Copy 'publisher ID' and paste to 'adUnitId'.

AndroidManifest.xml

  1. .........
  2. <uses-permission android:name="android.permission.INTERNET"/>
  3. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  4.     <application
  5.        ..........
  6.       >
  7.          .........
  8.         <activity
  9.            android:name="com.google.ads.AdActivity"
  10. android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
  11.        
  12.        </application>
  13. .....


This image is  running app. 

You can be seen to add adMob in your app.