select a.id, a.title, a.subtitle, a.createddate, a.user_id,
u.username, u.displayname, u.thumburl,
CONCAT(
'[',
GROUP_CONCAT(DISTINCT(
CONCAT(
CONCAT('{"id":"',m.id,'"'),
CONCAT(', "typecode":"',m.typecode,'"'),
CONCAT(', "thumburl":"',ifnull(m.thumburl,''),'"}')
)
) ORDER BY m.typecode, am.ordering ASC SEPARATOR ',' ),
']'
) as medias
from (
select id, title, subtitle, createddate, user_id from article
where user_id in (select user_id from follow where follow_user_id = 33 OR user_id = 33)
) as a
left join article_media as am on a.id = am.article_id
left join media as m on am.media_id = m.id
left join (
select u.id, u.username, u.displayname, u.picture_id, m.thumburl
from (
select id, username, displayname, picture_id from user
where id in (select user_id from follow where follow_user_id = 33 OR user_id = 33)
) as u
left join media as m on u.picture_id = m.id
) as u on a.user_id = u.id
where u.username != 'root'
group by a.id
Thursday, January 29, 2015
Wednesday, January 21, 2015
windows batch file using echo current directory or file
@echo off
echo ------------------------------
echo %cd%
:: folder
echo %~dp0%0
:: folder\ + filename.bat
echo %~f0
:: filefullname.bat
echo %~dpn0
:: filefullname
echo %~n0
:: filename
echo ------------------------------
echo ------------------------------
echo %cd%
:: folder
echo %~dp0%0
:: folder\ + filename.bat
echo %~f0
:: filefullname.bat
echo %~dpn0
:: filefullname
echo %~n0
:: filename
echo ------------------------------
Sunday, January 18, 2015
android custom textview with round stroke drawing
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint.Join;
import android.graphics.Paint.Style;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.widget.TextView;
import com.hiimeloyun.android.R;
/**
*
* @author boroo
*/
public class StrokeTextView extends TextView {
private final int strokeColor;
private final float strokeWidth;
TextPaint paint = new TextPaint();
public StrokeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.StrokeStyleable, 0, 0);
strokeWidth = a.getDimension(R.styleable.StrokeStyleable_strokeWidth, 10);
strokeColor = a.getColor(R.styleable.StrokeStyleable_strokeColor, Color.BLACK);
}
// overridden methods
@Override
protected void onDraw(Canvas canvas) {
final ColorStateList textColor = getTextColors();
paint = this.getPaint();
paint.setStyle(Style.STROKE);
paint.setStrokeJoin(Join.ROUND);
paint.setStrokeMiter(10);
this.setTextColor(strokeColor);
paint.setStrokeWidth(strokeWidth);
super.onDraw(canvas);
paint.setStyle(Style.FILL);
setTextColor(textColor);
super.onDraw(canvas);
}
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint.Join;
import android.graphics.Paint.Style;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.widget.TextView;
import com.hiimeloyun.android.R;
/**
*
* @author boroo
*/
public class StrokeTextView extends TextView {
private final int strokeColor;
private final float strokeWidth;
TextPaint paint = new TextPaint();
public StrokeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.StrokeStyleable, 0, 0);
strokeWidth = a.getDimension(R.styleable.StrokeStyleable_strokeWidth, 10);
strokeColor = a.getColor(R.styleable.StrokeStyleable_strokeColor, Color.BLACK);
}
// overridden methods
@Override
protected void onDraw(Canvas canvas) {
final ColorStateList textColor = getTextColors();
paint = this.getPaint();
paint.setStyle(Style.STROKE);
paint.setStrokeJoin(Join.ROUND);
paint.setStrokeMiter(10);
this.setTextColor(strokeColor);
paint.setStrokeWidth(strokeWidth);
super.onDraw(canvas);
paint.setStyle(Style.FILL);
setTextColor(textColor);
super.onDraw(canvas);
}
}
Thursday, January 15, 2015
Selector, Layer-list and shape/bitmap in the same xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item>
<shape android:shape="rectangle">
<size android:width="90dp" android:height="90dp" />
<solid android:color="#9933CC" />
</shape>
</item>
<item>
<bitmap android:gravity="center" android:src="@drawable/main_achievements_synthesis" />
</item>
</layer-list>
</item>
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<size android:width="90dp" android:height="90dp" />
<solid android:color="#AA66CC" />
</shape>
</item>
<item>
<bitmap android:gravity="center" android:src="@drawable/main_achievements_synthesis" />
</item>
</layer-list>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<selector>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<size android:width="90dp" android:height="90dp" />
<solid android:color="#9933CC" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<size android:width="90dp" android:height="90dp" />
<solid android:color="#AA66CC" />
</shape>
</item>
</selector>
</item>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/main_achievements_synthesis" />
</item>
</layer-list>
version2
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="5dp"/>
<solid android:color="#D0D0D0"/>
</shape>
</item>
<item>
<inset android:insetBottom="2dp">
<selector>
<item android:state_pressed="false">
<shape android:shape="rectangle">
<corners android:radius="3dp"/>
<solid android:color="#006600" />
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<corners android:radius="3dp"/>
<solid android:color="#003300" />
</shape>
</item>
</selector>
</inset>
</item>
</layer-list>
Wednesday, January 14, 2015
how to convert video file to types using ffmpeg library
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
namespace boroo.ffmpeg.example
{
class Program
{
const string InputDir = @"E:\\inputs\\";
const string OutputDir = @"E:\\outputs\\";
const string FFmpegPath = @"C:\\ffmpeg\\bin\\ffmpeg.exe";
bool isCompleted = false;
List<Process> processList = new List<Process>();
static void Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
Program p = new Program();
p.start(args);
Console.ReadLine();
}
public void start(string[] args)
{
string dirPath = InputDir;
if (args != null && args.Length > 0)
{
dirPath = args[0];
}
Thread thread = null;
while (!isCompleted)
{
if (thread == null)
{
thread = new Thread(convertProcess);
thread.Start(dirPath);
}
Thread.Sleep(2000);
}
}
// private method
private void convertProcess(object param)
{
isCompleted = false;
Console.WriteLine("Хөрвүүлэлт эхэллээ.");
string dirPath = (string)param;
DirectoryInfo dir = new DirectoryInfo(dirPath);
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
convertFile(file);
}
isCompleted = true;
killInterruptProcess();
Console.WriteLine("Хөрвүүлэлт дууслаа.");
}
private void convertFile(FileInfo file)
{
string fileTitle = Path.GetFileNameWithoutExtension(file.Name);
string extension = file.Extension;
string srcFilePath = file.FullName;
if (extension == ".mp4" || extension == ".avi")
{
Console.WriteLine("===========================================================================");
Console.WriteLine("Хөрвүүлэх файл олдлоо: '{0}'.", file.Name);
String destPath = OutputDir + fileTitle;
try
{
Process proc1 = createProcess(srcFilePath, destPath, "webm");
processList.Add(proc1);
proc1.WaitForExit();
proc1.Close();
processList.Remove(proc1);
if (extension == ".avi")
{
Process proc2 = createProcess(srcFilePath, destPath, "mp4");
processList.Add(proc2);
proc2.WaitForExit();
proc2.Close();
processList.Add(proc2);
}
}
catch (Exception ex)
{
Console.WriteLine("Алдаа: '{0}'.", ex.Message);
killInterruptProcess();
}
Console.WriteLine("Файлыг хөрвүүлж дууслаа: '{0}'.", file.Name);
Console.WriteLine("===========================================================================");
}
else
{
Console.WriteLine("Хөрвүүлэх шаардлагад нийцэхгүй файл олдлоо.");
Console.WriteLine("Файлыг устгаж байна. '{0}'.", file.FullName);
File.Delete(file.FullName);
}
}
void killInterruptProcess()
{
foreach(Process p in processList)
{
try
{
p.Kill();
}
catch { }
}
processList.Clear();
}
Process createProcess(string srcFilePath, string destPath, string toType)
{
Process proc = new Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = FFmpegPath;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.Arguments = "-i \"" + srcFilePath + "\" \""
+ destPath + (toType.StartsWith(".") ? toType : "." + toType) + "\" -y";
proc.Start();
return proc;
}
}
}
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
namespace boroo.ffmpeg.example
{
class Program
{
const string InputDir = @"E:\\inputs\\";
const string OutputDir = @"E:\\outputs\\";
const string FFmpegPath = @"C:\\ffmpeg\\bin\\ffmpeg.exe";
bool isCompleted = false;
List<Process> processList = new List<Process>();
static void Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
Program p = new Program();
p.start(args);
Console.ReadLine();
}
public void start(string[] args)
{
string dirPath = InputDir;
if (args != null && args.Length > 0)
{
dirPath = args[0];
}
Thread thread = null;
while (!isCompleted)
{
if (thread == null)
{
thread = new Thread(convertProcess);
thread.Start(dirPath);
}
Thread.Sleep(2000);
}
}
// private method
private void convertProcess(object param)
{
isCompleted = false;
Console.WriteLine("Хөрвүүлэлт эхэллээ.");
string dirPath = (string)param;
DirectoryInfo dir = new DirectoryInfo(dirPath);
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
convertFile(file);
}
isCompleted = true;
killInterruptProcess();
Console.WriteLine("Хөрвүүлэлт дууслаа.");
}
private void convertFile(FileInfo file)
{
string fileTitle = Path.GetFileNameWithoutExtension(file.Name);
string extension = file.Extension;
string srcFilePath = file.FullName;
if (extension == ".mp4" || extension == ".avi")
{
Console.WriteLine("===========================================================================");
Console.WriteLine("Хөрвүүлэх файл олдлоо: '{0}'.", file.Name);
String destPath = OutputDir + fileTitle;
try
{
Process proc1 = createProcess(srcFilePath, destPath, "webm");
processList.Add(proc1);
proc1.WaitForExit();
proc1.Close();
processList.Remove(proc1);
if (extension == ".avi")
{
Process proc2 = createProcess(srcFilePath, destPath, "mp4");
processList.Add(proc2);
proc2.WaitForExit();
proc2.Close();
processList.Add(proc2);
}
}
catch (Exception ex)
{
Console.WriteLine("Алдаа: '{0}'.", ex.Message);
killInterruptProcess();
}
Console.WriteLine("Файлыг хөрвүүлж дууслаа: '{0}'.", file.Name);
Console.WriteLine("===========================================================================");
}
else
{
Console.WriteLine("Хөрвүүлэх шаардлагад нийцэхгүй файл олдлоо.");
Console.WriteLine("Файлыг устгаж байна. '{0}'.", file.FullName);
File.Delete(file.FullName);
}
}
void killInterruptProcess()
{
foreach(Process p in processList)
{
try
{
p.Kill();
}
catch { }
}
processList.Clear();
}
Process createProcess(string srcFilePath, string destPath, string toType)
{
Process proc = new Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = FFmpegPath;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.Arguments = "-i \"" + srcFilePath + "\" \""
+ destPath + (toType.StartsWith(".") ? toType : "." + toType) + "\" -y";
proc.Start();
return proc;
}
}
}
how to upload my code folder into github community using git bush
open Git Bush from popup menu on windows
paste follow code...
git init
git add -A
git add *
git config user.email "email@example.com"
git config user.name "username"
git commit -m "commit description"
git remote add origin https://github.com/broject/CodeIgniterNuSoapSample.git
git push -f origin master
-f forse commit
paste follow code...
git init
git add -A
git add *
git config user.email "email@example.com"
git config user.name "username"
git commit -m "commit description"
git remote add origin https://github.com/broject/CodeIgniterNuSoapSample.git
git push -f origin master
-f forse commit
Wednesday, January 7, 2015
custom progress dialog make, custom linear progress bar drawing by custom design attributes
loading.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:whatever="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent">
<com.myapp.components.LoadingProgressBar
android:id="@+id/progressBar"
android:layout_width="fill_parent"
android:layout_height="5dp"
android:height="5dp"
whatever:strokeWidth="5dp"
whatever:strokeColor="@color/red"
/>
</LinearLayout>
themes.xml
<style name="dialogTheme" parent="@android:style/Theme.Dialog">
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="StrokeStyleable">
<attr name="strokeWidth" format="dimension" />
<attr name="strokeColor" format="color" />
</declare-styleable>
</resources>
LoadingDialog.java custom dialog
public class LoadingDialog extends Dialog {
public LoadingDialog(Context context) {
super(context, R.style.dialogTheme);
}
public void setProgress(int value) {
LoadingProgressBar linearProgressBar = (LoadingProgressBar) findViewById(R.id.progressBar);
if (linearProgressBar != null) {
linearProgressBar.setPercent(value);
}
}
}
LoadingProgressBar.java custom progressbar
public class LoadingProgressBar extends LinearLayout {
private final int mStrokeColor;
private final float mStrokeWidth;
private int percent;
Paint paint = new Paint();
public LoadingProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.StrokeStyleable, 0, 0);
mStrokeWidth = a.getDimension(R.styleable.StrokeStyleable_strokeWidth, 10);
mStrokeColor = a.getColor(R.styleable.StrokeStyleable_strokeColor, Color.WHITE);
}
public int getPercent() {
return percent;
}
public void setPercent(int percent) {
this.percent = (percent > 100 ? 100 : (percent < 0 ? 0 : percent));
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(mStrokeColor);
paint.setStrokeWidth(mStrokeWidth);
float w = getWidth();
float h = getHeight();
float pw = (percent < 10 ? 10 : percent) * w / 100;
canvas.drawLine(0, h - mStrokeWidth, pw, h - mStrokeWidth, paint);
}
}
activity code usage
private LoadingDialog loading;
protected void doLoading(int percent) {
if (loading == null) {
loading = new LoadingDialog(this);
loading.requestWindowFeature(Window.FEATURE_NO_TITLE);
loading.setContentView(R.layout.loading);
Window window = loading.getWindow();
window.setGravity(Gravity.TOP);
window.setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
loading.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface di) {
cancelTasks();
}
});
loading.show();
}
if (loading != null) {
loading.setProgress(percent);
}
}
protected void doLoaded() {
if (loading != null) {
loading.dismiss();
loading = null;
}
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:whatever="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent">
<com.myapp.components.LoadingProgressBar
android:id="@+id/progressBar"
android:layout_width="fill_parent"
android:layout_height="5dp"
android:height="5dp"
whatever:strokeWidth="5dp"
whatever:strokeColor="@color/red"
/>
</LinearLayout>
themes.xml
<style name="dialogTheme" parent="@android:style/Theme.Dialog">
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="StrokeStyleable">
<attr name="strokeWidth" format="dimension" />
<attr name="strokeColor" format="color" />
</declare-styleable>
</resources>
LoadingDialog.java custom dialog
public class LoadingDialog extends Dialog {
public LoadingDialog(Context context) {
super(context, R.style.dialogTheme);
}
public void setProgress(int value) {
LoadingProgressBar linearProgressBar = (LoadingProgressBar) findViewById(R.id.progressBar);
if (linearProgressBar != null) {
linearProgressBar.setPercent(value);
}
}
}
LoadingProgressBar.java custom progressbar
public class LoadingProgressBar extends LinearLayout {
private final int mStrokeColor;
private final float mStrokeWidth;
private int percent;
Paint paint = new Paint();
public LoadingProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.StrokeStyleable, 0, 0);
mStrokeWidth = a.getDimension(R.styleable.StrokeStyleable_strokeWidth, 10);
mStrokeColor = a.getColor(R.styleable.StrokeStyleable_strokeColor, Color.WHITE);
}
public int getPercent() {
return percent;
}
public void setPercent(int percent) {
this.percent = (percent > 100 ? 100 : (percent < 0 ? 0 : percent));
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(mStrokeColor);
paint.setStrokeWidth(mStrokeWidth);
float w = getWidth();
float h = getHeight();
float pw = (percent < 10 ? 10 : percent) * w / 100;
canvas.drawLine(0, h - mStrokeWidth, pw, h - mStrokeWidth, paint);
}
}
activity code usage
private LoadingDialog loading;
protected void doLoading(int percent) {
if (loading == null) {
loading = new LoadingDialog(this);
loading.requestWindowFeature(Window.FEATURE_NO_TITLE);
loading.setContentView(R.layout.loading);
Window window = loading.getWindow();
window.setGravity(Gravity.TOP);
window.setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
loading.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface di) {
cancelTasks();
}
});
loading.show();
}
if (loading != null) {
loading.setProgress(percent);
}
}
protected void doLoaded() {
if (loading != null) {
loading.dismiss();
loading = null;
}
}
Subscribe to:
Posts (Atom)